我试图删除多个文件。 我正在使用这个脚本,但由于某种原因它只删除了前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