我正在尝试创建一个图像文件名列表,按文件大小排序:
path = '/home/onur/Desktop/dataset/'
images = sorted(os.listdir(path), key = os.path.getsize)
print(images)
但我收到了这个错误:
Traceback (most recent call last):
File "/home/onur/Desktop/image-downloader.py", line 98, in <module>
images = sorted(os.listdir(path), key = os.path.getsize)
File "/usr/lib/python3.9/genericpath.py", line 50, in getsize
return os.stat(filename).st_size
FileNotFoundError: [Errno 2] No such file or directory: 'image_535.jpg'
python 文件不在/home/onur/Desktop/dataset/
. 它只是在桌面中,所以我想知道这是否是错误的原因。如果是这样,我该如何解决?