python 根据文件名删除文件

# -*- coding: utf-8 -*-
import os

def delete_file(dirname):
	filelist = os.listdir(dirname)
	for file in filelist:
		oldpath = os.path.join(dirname,file)
		filename = os.path.splitext(file)[0]#文件名
		filetype = os.path.splitext(file)[1]#文件类型
		if filename[0] == '_':
			os.remove(oldpath)
delete_file("F:\\保险条款\\txt")

 

你可能感兴趣的:(python,python)