我試圖刪除多個文件。 我正在使用這個腳本,但由於某種原因它只刪除了前4個而不是其他的。如果我將它分解爲2個腳本,它會起作用...我的問題是什麼?Python - 刪除多個文件
def fileDeleter():
try:
os.remove('apps.csv')
os.remove('columns.txt')
os.remove('columns_boot.txt')
os.remove('output.txt')
os.remove('routes.csv')
os.remove('route_apps.txt')
os.remove('route_domain.txt')
os.remove('route_hosts.txt')
os.remove('start.txt')
os.remove('space.txt')
except OSError:
pass
我的觀點是靜靜地處理它們,如果文件激發然後刪除 - 如果不通過。用戶不需要看到文件不存在的錯誤。當我說的錯誤,我得到的只有一個是
WindowsError: [Error 2] The system cannot find the file specified: *filename*
whice是好的,becuse我沒有所有的文件,所有的時間。但是當我這樣做時,腳本並不會刪除它們。
什麼是錯誤?我認爲這將有所幫助,如果'except:'不僅僅是'pass' – Ian