python - Errno 13 - 文档文件夹中的权限被拒绝?

标签 python io copy errno shutil

好吧,我在一个允许用户创建项目的代码上工作了一个小时,但现在我惊呆了。我尝试使用 shutilcopyfile 复制文件。这是我的代码:

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/

相关文章:

c# - 如何编写一个简单的 C# 脚本将文件复制到上一级目录?

python - 训练后如何保存/恢复模型?

python - Pandas : add a sublevel to an index that depend from the upper one

python - 如何匹配 pyPEG 中的无序事物?

c++ - C++ 中的缓冲区大小

c# - 如何在同一个 ListView 中拖放项目?

python - 使用注释时在 Django 中显示选择字段的名称

java - 将文件读入字符串 - Java

c++ - Windows C++ 上的 std::fstream 读取文件

objective-c - 属性复制在Cocoa框架中意味着什么?(如UITabBar的items属性)