我正在尝试将多个文件从一个目录复制到另一个目录中。
src_files = os.listdir("srcdir")
print(src_files)
for file_name in src_files:
full_file_name = os.path.join("srcdir", file_name)
if (os.path.isfile(full_file_name)):
shutil.copy(full_file_name, "destdir/")
但是我收到以下错误:
Traceback (most recent call last):
File "script.py", line 539, in <module>
buildGUI()
File "script.py", line 385, in buildGUI
shutil.copy(full_file_name, "destdir/")
File "/home/opt/lib/python3.4/shutil.py", line 228, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/home/opt/lib/python3.4/shutil.py", line 108, in copyfile
with open(dst, 'wb') as fdst:
IsADirectoryError: [Errno 21] Is a directory: '/home/destdir/'
我以为shutil.copy支持目标目录?这就是documentation所说的内容。
编辑: 基于评论,我想我应该在64位Debian Machine上添加这是Python3.4。
EDIT2: 作为一种解决方法,我只使用shutil.copytree(“sourcedir”,“destdir /”),这似乎有效。我会打开这个问题,并提交错误报告或其他内容,除非发布答案。