通过OS Shell使用python删除文件 [英] Delete files with python through OS shell
本文介绍了通过OS Shell使用python删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试删除E:中的所有文件. 与通配符.
Im Tyring to Delete all Files in E:. with wildcard.
E:\test\*.txt
我会问而不是测试os.walk. 在Windows中.
I would ask rather than test the os.walk. In windows.
推荐答案
另一种方法的详细描述
import os
dir = "E:\\test"
files = os.listdir(dir)
for file in files:
if file.endswith(".txt"):
os.remove(os.path.join(dir,file))
或
import os
[os.remove(os.path.join("E:\\test",f)) for f in os.listdir("E:\\test") if f.endswith(".txt")]
这篇关于通过OS Shell使用python删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文