[英]How to change a file's permissions/attributes to make it not readable in Windows with Python
我正在嘗試測試一些代碼,並對其進行測試,我需要在特定位置獲取異常:
def makeThisFunctionReturnTrue(filename):
if os.path.exists(input) and os.path.isfile(filename):
try:
open(filename, "r")
except IOError, err:
return True
return False
我需要弄清楚什么輸入文件名會使上面的函數返回True。 我認為解決方案在於更改文件中的權限或屬性。 通過Windows資源管理器進入文件的屬性,然后進入安全性,然后拒絕權限,我可以手動強制錯誤。 但是,我需要能夠在Python中動態創建文件,然后通過Python更改權限以強制錯誤。
我的第一個想法是使用os.chmod(); 但是,此功能在Windows環境中似乎受到限制。
我的一位同事建議我使用win32file.SetFileAttributes(),但是我找不到關於此函數的任何好的文檔。
謝謝您的幫助。
卡勒布·魯勒(Caleb Rouleau)
自己提出異常
raise IOError('SUITABLE INFO HERE')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.