【发布时间】:2012-07-01 22:42:24
【问题描述】:
我有一些使用 shutil.copyfile 的 python 代码:
import os
import shutil
src='C:\Documents and Settings\user\Desktop\FilesPy'
des='C:\Documents and Settings\user\Desktop\\tryPy\Output'
x=os.listdir(src)
a=os.path.join(src,x[1])
shutil.copyfile(a,des)
print a
它给了我一个错误:
IOError: [Errno 13] Permission denied: 'C:\\Documents and Settings\\user\\Desktop\\tryPy\\Output'
为什么我没有复制文件的权限?
【问题讨论】:
-
shutil.copyfile 将使用运行脚本的用户的权限运行。要么使用 sudo 运行 python 脚本,要么以 root 身份运行它,或者使用可以复制并在需要时将自身提升为 root 的不同库。
-
你可以看到这个解决方案:https://stackoverflow.com/a/53894504/9533909 解决了我同样的问题
标签: python permission-denied shutil