【发布时间】:2015-09-04 22:22:04
【问题描述】:
我正在尝试编写一个脚本,该脚本将自动删除特定文件夹中的所有临时文件,我注意到该脚本还删除了该文件夹中的所有 文本文件。谁能解释为什么会这样?
import os
path = 'C:\scripts27'
for root, dirs, files in os.walk(path):
for currentFile in files:
print "processing file: " + currentFile
extensions=('.tmp')
if any(currentFile.lower().endswith(ext) for ext in extensions):
os.remove(os.path.join(root, currentFile))
我在 Windows 8.1 PC 64 位上使用 Python 2.7.10 运行此脚本。
谢谢!
【问题讨论】:
标签: python python-2.7 os.walk os.path