我正在使用以下代码将文件夹PStool
的内容复制到文件夹c:/WINDOWS/System32
中。我以管理员身份运行程序
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')
获取
PermissionError: [error 13] permission denied : 'c:/WINDOWS/System32'
答案 0 :(得分:1)
copyfile()目标应该是完整的文件名。根据Python文档:
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.
尝试一下:
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)