Chinaunix首页 | 论坛 | 博客
  • 博客访问: 586412
  • 博文数量: 129
  • 博客积分: 6240
  • 博客等级: 准将
  • 技术积分: 1765
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-18 15:42
文章分类

全部博文(129)

文章存档

2015年(1)

2012年(3)

2011年(6)

2010年(14)

2009年(105)

我的朋友

分类: WINDOWS

2009-03-27 10:31:16

结合VBS就比较简单了。是否只需要处理10天前那一天的文件夹,还是所有。。救你的例子,今天8月5日,7月24日、7月23日...等等是否删除?如果只是当天的话,下面的代码就可以了(与要删除的文件夹放在同一目录):

@echo off
echo wscript.echo dateadd("d",-10,date) >%tmp%\tmp.vbs
for /f "tokens=1,2,3* delims=-" %%i in ('cscript /nologo %tmp%\tmp.vbs') do (
set year=%%i
set month=%%j
if !month! LSS 10 set month=0%%j
set day=%%k
if !day! LSS 10 set day=0%%k
)
rd /s /q %year%-%month%-%day%
echo 删除成功,按任意键退出。&pause >nul 2>nul
 
 
 
 
这个批处理会不太精确的删除五天前的文件,不会删除子文件夹内的文件,不会区分月份只按日期删除,测试通过.


@echo off
setlocal enabledelayedexpansion
set folder=你要检查的文件夹路径,比如C:\windows\temp

set currentdate=%date:~8,2%
if "!currentdate:~0,1!"=="0" set currentdate=!currentdate:~1,1!
for /f "eol= delims=" %%i in ('dir /a:-d "%folder%"') do (
set file=%%i
set filedate=!file:~8,2!
if "!filedate:~0,1!"=="0" set filedate=!filedate:~1,1!
set /a filedate=!currentdate!-!filedate!
if !filedate! LSS 0 set /a filedate=!filedate!+28
if !filedate! GTR 5 del /f /a "!file:~36!"
)
pause
exit
阅读(2560) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~