python脚本 删除2天前后缀为.log的文件 #!/usr/local/python/bin/python #-*-coding=utf8 -*- import time import os,sys N = 2 #设置删除多少天前的文件 def deletefile(path): for eachfile in os.listdir(path): filename = os.path.join(path,eachfile) if os.path.isfile(filename): lastm…
python版本为:2.7 import os import sys import time # Sets how many days old files are deleted DAYS_N = 7 # To delete the path and the following subfiles PATH = r'C:\inetpub\logs\LogFiles' def deletefile(PATH): for eachfile in os.listdir(PATH): filename =…
#获取所有文件def file(): for cur_dir, dirs, files in os.walk(r'/学习/接口自动化/BestTest/作业/logs'): # cur_dir(当前路径),dirs(目录),files(文件)中所有的 for file in files: abs_path = os.path.join(cur_dir, file) # 获取绝对路径 if int(timestamp_to_str(abs_path.split("_")[1].split…
import os import time import datetime def should_remove(path, pattern, days): if not path.endswith(pattern): return False mtime = os.path.getmtime(path) now = time.time() result = now - mtime > days * 24 * 3600 print "\n>>>>>>>…
shell程序如下所示: # cat xarg.txt #! /usr/bin/ksh for logfile in `find . -name "*.log*"` do echo "$logfile:" sed -n '/error/=' $logfile done files=($(find . -name "*log*")) echo "The length is ${#files[@]}" for file in ${…