在python中取消多个文件的链接

2024-06-17 10:20:16 发布

您现在位置:Python中文网/ 问答频道 /正文

Possible Duplicate:
Deleting files by type in Python on Windows

如何删除目录中扩展名为“.txt”的所有文件?我通常只是

import os
filepath = 'C:\directory\thefile.txt'
os.unlink(filepath)

是否有像os.unlink('C:\ directory\'*.txt)这样的命令可以删除所有.txt文件?我该怎么做? 谢谢!


Tags: 文件intxtbyosonwindowstype