需求: 在测试程序的时候,程序会大批量的上传文件到规定目录,然后文件根据日期DAY新建文件夹存放,比如28号上传的文件放到 .../28/* 内,29号上传的文件放到 .../29/*内,因为需要测试持续上传3天,而磁盘空间有限,必须删除上传完的文件,确保空间足够. 实现: 自己能用就好,不需要通用. #-*-coding=gbk -*- import os import time def listDir(fileDir): for eachFile in os.listdir(fileD
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 =
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
原文:用批处理文件自动备份文件及文件夹,并自动删除n天前的文件 ---恢复内容开始--- 下是备份的批处理,添加到"计划任务"中,设定时间自动运行 复制代码 代码如下:@echo off rem 格式化日期 rem date出来的日期是"2006-02-22 星期三",不能直接拿来使用,所以应该先格式化一下 rem 变成我们想要的.date:~0,4的意思是从0开始截取4个字符 set d=%date:~0,4%%date:~5,2%%date:~8,2% rem