![](/img/trans.png)
[英]Python - PermissionError: [WinError 5] Access is denied:
[英]PermissionError: [WinError 5] Access is denied in Python
import shutil
def create_dir(path):
if not os.path.exists(path):
os.mkdir(path)
else:
shutil.rmtree(path)
當我運行此代碼時,即使我有權訪問該目錄,它也會給我權限錯誤。
另外,我使用 Windows 並嘗試以管理員身份運行
檢查文件夾是否不是只讀的。
或者你也可以運行命令:
import os
os.system('whoami')
它將顯示哪個用戶當前注冊為啟動用戶。
嘗試使用 ignore_errors=True,
import shutil
def create_dir(path):
if not os.path.exists(path):
os.mkdir(path)
else:
shutil.rmtree(path, ignore_errors = True)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.