『第
4 楼』:
(1) 以下是我测试的code , 初步测试可行,但须第三方
(2) 请各位可否精简,不要暂存档,谢谢 !
del 2.bat
del 3.bat
call robocopy-01.bat
call move-01.bat >> 2.bat
call change01.bat
call rep-string02.bat
ping 127.1 -n 3 > nul
start 3.bat robocopy-01.bat (复制目录架构,不含档案,robocopy是微软工具 ) :
robocopy d:\temp02 D:\Temp1\test\test99 /e /lev:50 /minage:19000101
move-01.bat (修改cn-dos的 delete sample 为move):
@echo off
::演示:echo move 指定路径下指定天数之前(以档的最后修改日期为准)的档。
::如果演示结果无误,把move前面的echo去掉,即可实现真正删除。
::本例调用了临时VBS代码进行日期计算,并统一设置系统日期格式,处理完毕
::之后再把日期格式恢复成原来的状态。摆脱了对reg命令(XP系统自带)的依赖。
rem 指定待move文件的存放路径
set SrcDir=D:\temp02
rem 指定天数
set DaysAgo=30
>"%temp%\BackupDate.vbs" echo Set WshShell = WScript.CreateObject("WScript.Shell")
>>"%temp%\BackupDate.vbs" echo WScript.Echo WshShell.RegRead ("HKEY_CURRENT_USER\Control Panel\International\sShortDate")
for /f %%a in ('cscript /nologo "%temp%\BackupDate.vbs"') do (
set "RegDateOld=%%a"
)
>"%temp%\UnifyDate.vbs" echo Set WshShell = WScript.CreateObject("WScript.Shell")
>>"%temp%\UnifyDate.vbs" echo WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\sShortDate", "yyyy-M-d", "REG_SZ"
cscript /nologo "%temp%\UnifyDate.vbs"
>"%temp%\DstDate.vbs" echo LastDate=date()-%DaysAgo%
>>"%temp%\DstDate.vbs" echo FmtDate=right(year(LastDate),4) ^& right("0" ^& month(LastDate),2) ^& right("0" ^& day(LastDate),2)
>>"%temp%\DstDate.vbs" echo wscript.echo FmtDate
for /f %%a in ('cscript /nologo "%temp%\DstDate.vbs"') do (
set "DstDate=%%a"
)
set DstDate=%DstDate:~0,4%-%DstDate:~4,2%-%DstDate:~6,2%
for /r "%SrcDir%" %%a in (*.*) do (
if "%%~ta" leq "%DstDate%" (
if exist "%%a" (
echo move "%%a" "%%a"
)
)
)
>"%temp%\RecoverDate.vbs" echo Set WshShell = WScript.CreateObject("WScript.Shell")
>>"%temp%\RecoverDate.vbs" echo WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\International\sShortDate", "%RegDateOld%", "REG_SZ"
cscript /nologo "%temp%\RecoverDate.vbs" change01.bat (change为第三方工具):
change 2.bat /from " /to ☆
rep-string02.bat (replace ☆ to "):
@echo off
setlocal enabledelayedexpansion
for /f "usebackq tokens=1,2,3,4 delims=☆" %%a in (2.bat) do (
set str=%%d
REM set str=!str:D:\temp02=D:\Temp1
set str=!str:D:\temp02=D:\Temp1\test\test99!
echo %%a "^%%b" "!str!" >>3.bat
) [ Last edited by pdanniel66 on 2010-7-13 at 05:29 ]
|