1. 程式人生 > >python 根據檔名刪除檔案

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")