删除当前目录下特定类型的文件
#
#function: del all files with specific type in current dir
#
import os
import os.path
type=raw_input('input file type:')
if not '.' in type:
type='.'+type
cwd=os.getcwd()
print 'current path'+cwd
filelist=os.listdir(cwd)
for file in filelist:
if type in file:
print file
answer=raw_input('Confirmed to del these files ?(yes/no)')
if answer=='yes':
for file in filelist:
if type in file:
os.remove(file)
python 删除文件
最新推荐文章于 2024-07-23 19:23:47 发布