Trying to simply sort two directories, and it works fine the first time, but when I call it a second time (last line below, for tallFiles
), it throws a 'No such file or directory
error, even though it correctly lists the first sorted file in that directory.
import os
import datetime
from pathlib import Path
wallDir = Path('/Users/leigh/Dropbox/Photos/Wallpaper')
tallDir = Path('/Users/leigh/Dropbox/Photos/Wallpaper/Tall')
wallFiles = sorted(os.listdir(wallDir), key=lambda t: -os.stat(t).st_mtime)
tallFiles = sorted(os.listdir(tallDir), key=lambda t: -os.stat(t).st_mtime)
Throws this error:
leigh@outpost31 Wallpaper % python3 ~/Dropbox/Development/rename.py
Traceback (most recent call last):
File "/Users/leigh/Dropbox/Development/rename.py", line 9, in <module>
tallFiles = sorted(os.listdir(tallDir), key=lambda t: -os.stat(t).st_mtime)
File "/Users/leigh/Dropbox/Development/rename.py", line 9, in <lambda>
tallFiles = sorted(os.listdir(tallDir), key=lambda t: -os.stat(t).st_mtime)
FileNotFoundError: [Errno 2] No such file or directory: 'holjfmgopwk81.jpg'
The file and path absolutely exist...