Reputation: 21
I'am using the following code to copy content of folder PStool
into folder c:/WINDOWS/System32
. I am running the program as admin
import shutil
import os
programSourcePath = "C:\Users\Admin\Desktop\Utilities_Installers_new\Programs"
pstoolfiles = os.listdir(programSourcePath + '/PSTools')
for name in pstoolfiles:
srcname = os.path.join(programSourcePath + '/PSTools', name)
shutil.copyfile(srcname, r'c:/WINDOWS/System32')
Getting
PermissionError: [error 13] permission denied : 'c:/WINDOWS/System32'
Upvotes: 0
Views: 312
Reputation: 11
copyfile() destination should be complete filename. As per Pythons docs:
shutil.copyfile(src, dst) Copy the contents (no metadata) of the file named src to a file named dst. dst must be the complete target file name; look at shutil.copy() for a copy that accepts a target directory path.
Try this:
import shutil
import os
programSourcePath = "C:\Users\Admin\Desktop\Utilities_Installers_new\Programs"
pstoolfiles = os.listdir(programSourcePath + '/PSTools')
for name in pstoolfiles:
srcname = os.path.join(programSourcePath + '/PSTools', name)
dstname = os.path.join(r'c:/WINDOWS/System32', name)
shutil.copyfile(srcname, dstname)
Upvotes: 1