我需要創建一個不存在的子目錄,然後將一些文件複製到其中。然而,每當我嘗試時,我都會得到一個Permission denied錯誤。我試過chmod,777以及stat.S_IWRITE,我試過os.system('attrib -r),但沒有任何效果。任何人都可以幫我解決這個問題嗎?我知道網站上有類似的問題,但它說使用chmod,這不適合我。使用Python在Windows中創建可寫目錄os.makedirs
這裏是我的代碼:
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)
如果你喜歡你得到的答案,請檢查它,以便這個傢伙得到點數! –