Okay, I worked for an hour on an code which allows the user to create an project, but now I am stunning. I try to copy a file using shutil
and copyfile
. Here is my code:
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()
And for starting:
if __name__ == '__main__':
adder = Adder()
adder.AddResource('/users/jan/downloads/', 'polygon_grey_background.jpg', '/users/jan/documents/', 'MyCoolScene')
But now I get the following problem:
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'
It means that I don't have the permission to copy the file? But its my Documents
folder? How can I fix this?
~Jan
通过使用copy
而不是copyfile
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.