我有一个名为fileList的列表,其中包含成千上万个文件名和大小,类似于这样:
['/home/rob/Pictures/some/folder/picture one something.jpg', '143452']
['/home/rob/Pictures/some/other/folder/pictureBlah.jpg', '473642']
['/home/rob/Pictures/folder/blahblahpicture filename.jpg', '345345']
我想使用fileList [0]作为源来复制文件到另一个完整的目标位置。类似于:
copyFile(fileList[0], destinationFolder)
并将文件复制到该位置。
当我这样尝试时:
for item in fileList:
copyfile(item[0], "/Users/username/Desktop/testPhotos")
我遇到了如下的错误:
with open(dst, 'wb') as fdst:
IsADirectoryError: [Errno 21] Is a directory: '/Users/username/Desktop/testPhotos'
有什么东西可以让我解决这个问题呢?我是在 Mac 和 Linux 上使用 Python 3。
os
包进行路径操作。 - mikuszefskicopy
函数可以接受文件夹作为目标。 - mikuszefski