1. 程式人生 > >使用Python刪除Windows中只讀檔案

使用Python刪除Windows中只讀檔案

在Windows中,刪除只讀檔案有兩種方法:

1. 修改只讀屬性,再刪除:

os.chmod( filename, stat.S_IWRITE )
os.remove(filename)

2. 使用命令列:
os.system("DEL filename /F")

但是在Linux和Mac中,檔案的許可權分三種:Write,Read,Execution。只要包含這個檔案的資料夾是Write許可權,則不管該檔案是否是隻讀,都可以刪除該檔案。這點是與Windows的不同之處。