好吧,我在一个允许用户创建项目的代码上工作了一个小时,但现在我惊呆了。我尝试使用 shutil
和 copyfile
复制文件。这是我的代码:
class Adder():
@staticmethod
def AddResource(resourcepath,resourcename,rootpath,projectname):
resfi = rootpath + projectname + "/" + projectname + ".sceneproj/Resources"
resfo = rootpath + projectname + "/" + projectname + ".sceneproj/project.scresources"
shutil.copyfile(resourcepath + resourcename, resfo) # copy resource into resource folder
with open(resfi, 'a') as resfile:
resfile.write("project.scresources/" + resourcename)
resfile.close()
开始:
if __name__ == '__main__':
adder = Adder()
adder.AddResource('/users/jan/downloads/', 'polygon_grey_background.jpg', '/users/jan/documents/', 'MyCoolScene')
但现在我遇到了以下问题:
Traceback (most recent call last): File "project.py", line 28, in adder.AddResource('/users/jan/downloads/', 'polygon_grey_background.jpg', '/ users/jan/documents/', 'MyCoolScene') File "project.py", line 21, in AddResource shutil.copyfile(resourcepath + resourcename, resfo) # copy resource into res ource folder File "C:\Python27\lib\shutil.py", line 83, in copyfile with open(dst, 'wb') as fdst: IOError: [Errno 13] Permission denied: '/users/jan/documents/MyCoolScene/MyCoolS cene.sceneproj/project.scresources'
意思是我没有复制文件的权限?但它是我的 Documents
文件夹?我该如何解决这个问题?
~简
最佳答案
通过使用 copy
而不是 copyfile
修复了这个问题。
关于python - Errno 13 - 文档文件夹中的权限被拒绝?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28250993/