I know this question is asked and answered many places on this site but none of the resolutions work for me. Basically, I need shutil.copy to work the same way as shutil.move works (and it does) but when I do .copy I get the Error 13 Permissions error on the source file.
I can't do shutil.copytree because I need not the content of the first file folder to be copied but the file folder itself (with the contents inside). I've tried checking the permissions, modifying, nothing works.
I've also tried using the full path including the folder names (no variables) and I still get the same error.
This is in Windows 7 and 8.1
Here is the code:
import os
import csv
import re
from os import path
from distutils.dir_util import copy_tree
import shutil
# Open the csv file
f = open("Consumers.csv")
csv_f = csv.reader(f)
#Loop throught the csv file
for eachrow in csv_f:
#loop through the folders in the directory
for foldname in os.listdir():
#If the folder name is the same as a field in the first column of the csv file
if (foldname == eachrow[0]):
#Name the second column filed name "bucket."
#This is also the name of a folder in the same directory
bucket = eachrow[1]
#copy the first folder (and contents) into the second folder
shutil.copy (foldname, bucket)
And the error:
PermissionError Traceback (most recent call last)
<ipython-input-36-61e009418603> in <module>
25
26 #copy the first folder (and contents) into the second folder
---> 27 shutil.copy (foldname, bucket)
28
29
~\Anaconda3\lib\shutil.py in copy(src, dst, follow_symlinks)
243 if os.path.isdir(dst):
244 dst = os.path.join(dst, os.path.basename(src))
--> 245 copyfile(src, dst, follow_symlinks=follow_symlinks)
246 copymode(src, dst, follow_symlinks=follow_symlinks)
247 return dst
~\Anaconda3\lib\shutil.py in copyfile(src, dst, follow_symlinks)
118 os.symlink(os.readlink(src), dst)
119 else:
--> 120 with open(src, 'rb') as fsrc:
121 with open(dst, 'wb') as fdst:
122 copyfileobj(fsrc, fdst)
PermissionError: [Errno 13] Permission denied: 'Last1_First1_11111'
Any help would be greatly appreciated!