I am trying to copy multiple files from one directory, into another directory.
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/")
However I am getting the following error:
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/'
I thought shutil.copy supported a target directory? Thats what the documentation says.
EDIT: Based on comment, think I should add that this is Python3.4 on a 64bit Debian Machine.
EDIT2: As a workaround I'll just use shutil.copytree("sourcedir", "destdir/") which seems to work. I'll leave this question open, and file a bug report or something unless an answer is posted.