脚本展示:
#!/usr/bin/env python
#coding:utf-8
import time,sys,re,os,datetime
DELETE_FILE_DATE = datetime.datetime.now() - datetime.timedelta(days=8)
DELETE_FILE_DATE=DELETE_FILE_DATE.strftime(‘%Y%m%d‘)
FILE_DIRECTORY=sys.argv[1]
FILE_NAME=sys.argv[2]
result = re.findall(‘\w\s‘,FILE_NAME)
MATCH_NAME=‘‘.join(result)
FILE_LIST=os.listdir(FILE_DIRECTORY)
for i in FILE_LIST:
if MATCH_NAME in i:
FILEMT=time.localtime(os.stat(i).st_mtime)
DATE=time.strftime("%Y%m%d",FILEMT)
if DELETE_FILE_DATE > DATE:
os.remove(i)
执行展示:
时间: 2024-12-30 03:14:12