I need to copy some documents, folders and files from one directory on my local drive to all connected USB flash drives.
When destination is also folder everything works but in case the destination is USB drive root then I always get error:
Error: [WinError 5] Access denied: 'E:\\'
I think problem is in second backslash.
import wmi
import os
import shutil
import pathlib
import errno
src = pathlib.WindowsPath("c:/FLASH")
def clone(src, dst):
try:
shutil.copytree(src, dst)
except OSError as e:
if e.errno == errno.ENOTDIR:
shutil.copy(src, dst)
elif e.errno == errno.EACCES:
print('Error: %s' % e)
else:
print('Error: %s' % e)
c = wmi.WMI()
for drive in c.Win32_LogicalDisk():
print(drive.Caption, drive.Description)
if drive.DriveType == 2:
dst = pathlib.PureWindowsPath(drive.Caption, '\\')
clone(src, dst)