'Shutil.copy not working after use os.walk()
I have tried to run the code with the fix path at the beginning. After it able to work, I change it to walk through directory (folders & sub-folders). Now it doesn't run with error, but the shutil.copy line doesn't copy the files.
BEFORE:
for i, dwgfile in enumerate(newdwglist, start=0):
dwgfile = newdwglist[i]
os.chdir('C:\\Users\\chinhing\\test folder\\source folder')
if os.path.exists(dwgfile):
shutil.copy(dwgfile, destlink)
else:
i = i + 1
missdwg.append(dwgfile)
AFTER:
for i, dwgfile in enumerate(newdwglist, start=0):
dwgfile = newdwglist[i]
for roots, dirs, files in os.walk(mainpath):
for dwg in files:
if dwg == dwgfile:
if os.path.exists(dwgfile):
shutil.copy(dwgfile, destlink) #notworking
print(os.path.join(destlink, dwgfile))
else:
missdwg.append(dwgfile)
else:
i = i + 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
