How to delete files using the syntax '*' with python3?
There are some files that named like percentxxxx.csv,percentyyyy.csv in the dir.I want to delete the files with the name begins with percent.
I find the os.remove
function maybe can help me,bu I don't konw how to solve the problem.
Are there any other functions can delete files using the syntax percent*.csv ?
The following is my method:
system_dir=os.getcwd()
for fname in os.listdir(system_dir):
# print(fname)
if fname.startswith('report'):
os.remove(os.path.join(system_dir, fname))
I mainly want to know whether there are more easier methed ,for example using * syntax in the method.
使用glob:
import os
import glob
for csv in glob.glob("percent*.csv"):
os.remove(csv)
链接地址: http://www.djcxy.com/p/42422.html
上一篇: 在python中删除特定的行和相应的文件
下一篇: 如何用python3语法'*'删除文件?