用Python脚本:根据文件列表“stab_case.txt”上面的文件名称,删除指定文件夹(包括子文件夹)下面的文件。
#coding=utf-8
import os
WORKDIR = os.getcwd()#不必修改
#提供局排错误案例信息的报告全集,除非生成的报告名改变否则不必改动
g_ResultTxtName = ['stab_case.txt', ]
#如果把该程序拷到Cases\\Case下则不需要设置
#否则写成如这样的案例存放的绝对路径'E:\\render\\Cases\\Case'
CasePath = WORKDIR
def deleteFile(filepath):
try:
if not os.path.exists(filepath):
print filepath, "not exist!"
return 0
if not os.path.isfile(filepath):
print filepath, "is not a file!"
return 0
os.remove(filepath)
print "Delete ", filepath, " suclearcase/" target="_blank" >cceded!"
return 1
except:
print "Delete ", filepath, " failed!"
pass
return 0
def analyseReport(txtPath):
pathList = []
try:
report = open(txtPath,'r')
except Exception,ex:
print str(Exception),':',str(ex)
report.close()
return pathList
for line in report:
if len(line) <= len('\n'):
continue
#line = line.decode('cp936')
pathList.append(line[:-1])#去掉开头的\t和最后的\n
report.close()
pathList.sort()
return pathList
if '__main__' == __name__:
for item in g_ResultTxtName:
txtPath = os.path.join(WORKDIR, item)
pathList = []
if os.path.exists(txtPath):
pathList = analyseReport(txtPath)
for Path in pathList:
docPath = os.path.join(CasePath, Path)
deleteFile(docPath)
print 'Delete Over'
os.system("pause")