如果它不存在,我需要创建一个子目录,然后将一些文件复制到它中。然而,每当我尝试时,我都会得到一个Permission denied错误。我试过chmod,777以及stat.S_IWRITE,我试过os.system('attrib -r),但没有任何效果。任何人都可以帮我解决这个问题吗?我知道网站上有类似的问题,但它说使用chmod,这不适合我。
这是我的代码:
beginpath = "C:\Users\foo"
fullpath = os.path.join(beginpath, foldername)
print fullpath
fullpath = fullpath.replace('\n', '')
##create a folder to hold the deleted files
deleted = os.path.join(fullpath, "Deleted")
print deleted
if not os.path.exists(deleted):
os.makedirs(deleted)
os.chmod(deleted, stat.S_IWRITE)
print "created"
##do some other processing here
oldfile = os.path.join(fullpath, newpagename)
shutil.copyfile(oldfile, deleted)