查看单个帖子
hitme
 
hitme 的头像
支柱会员
 
资 料:
注册日期: Oct 2001
帖子: 6,489 声望值: 2
精华: 38,解答: 6
#1 旧 2005-04-30, 19:39:41 默认 【原创】批量删除文件修改时间为n天前的文件
hitme 当前离线  

copy自yesterday.vbs
搞不明白如何将vbs变量传递给cmd变量,算了,用for...('cscript.exe..)..来取了

用法:cmd下

del_day 5

删除文件修改时间为5天前的文件,测试,删除操作务必谨慎
代码:
@echo off

>t_day.vbs  echo ' Yesterday.vbs,  Version 1.01                          
>>t_day.vbs echo '                                                      
>>t_day.vbs echo ' Written by Rob van der Woude                         
>>t_day.vbs echo ' http://www.robvanderwoude.com                        
>>t_day.vbs echo '                                                     
>>t_day.vbs echo ' Calculate yesterday's date                           
>>t_day.vbs echo    dtmYesterday = DateAdd("d",-%1,Date)              
>>t_day.vbs echo '                                                      
>>t_day.vbs echo ' Get yesterday's year                                 
>>t_day.vbs echo    strYear      = DatePart("yyyy",dtmYesterday)        
>>t_day.vbs echo '                                                    
>>t_day.vbs echo ' Get yesterday's month, add leading zero if necessary 
>>t_day.vbs echo    If DatePart("m",dtmYesterday) ^< 10 Then            
>>t_day.vbs echo 	   strMonth = 0 ^& DatePart("m",dtmYesterday)       
>>t_day.vbs echo    Else                                                
>>t_day.vbs echo 	   strMonth = DatePart("m",dtmYesterday)           
>>t_day.vbs echo    End If                                              
>>t_day.vbs echo '                                                      
>>t_day.vbs echo ' Get yesterday's day, add leading zero if necessary  
>>t_day.vbs echo    If DatePart("d",dtmYesterday) ^< 10 Then            
>>t_day.vbs echo	   strDay = 0 ^& DatePart("d",dtmYesterday)        
>>t_day.vbs echo    Else                                               
>>t_day.vbs echo	   strDay = DatePart("d",dtmYesterday)            
>>t_day.vbs echo    End If                                              
>>t_day.vbs echo '                                                     
>>t_day.vbs echo ' Format output for yesterday                          
>>t_day.vbs echo   strYest = strYear ^& strMonth ^& strDay             
>>t_day.vbs echo '                                                     
>>t_day.vbs echo ' echo                                                 
>>t_day.vbs echo Wscript.echo( strYest )                                

@echo on 
for /f "delims=" %%i in ('cscript.exe //nologo t_day.vbs') do set t_day=%%i
setlocal ENABLEDELAYEDEXPANSION
for /r %%i in (*.*) do set c_day=%%~ti && if "!c_day:~0,2!!c_day:~3,2!!c_day:~6,2!" lss "%t_day:~2,6%" del /q "%%i" 
endlocal
cls
@echo =========================
@echo 删除完毕.
@echo =========================
上传的附件
文件类型: rar del_day.rar (669 字节, 106 次查看)