我有一个名为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。
你可以只使用shutil.copy()命令:
e.g.
import shutil
for item in fileList:
shutil.copy(item[0], "/Users/username/Desktop/testPhotos")
[来自 Python 3.6.1 文档。我试过了,它有效。]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)