【发布时间】:2019-03-21 23:06:17
【问题描述】:
我有一个名为 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。
【问题讨论】:
-
看psytho的评论,看看
os的路径操作包。 -
docs.python.org/2/library/shutil.html
copy接受文件夹作为目标
标签: python python-3.x file-copying