这个批处理是删除指定天数日期之前的文件,但是只有批定一个文件夹,我有其他的几个文件夹也是同样要删除之前的文件,但是不知要怎么处理,哪位帮忙一下,先谢谢了,
@echo off
rem 还有其他文件夹内的文件要删除要怎么设呢?如:D:\LastPass\ F:\Temp\ 等等
rem 用SrcDir1=:D:\LastPass\ SrcDir2=F:\Temp\ 试了好象也不行 只能一个个来就正常了
set SrcDir=I:\Windows\TOP_2014\
rem 指定天数
set DaysAgo=6
>"%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" (
del /f /q "%%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"
@echo off
rem 还有其他文件夹内的文件要删除要怎么设呢?如:D:\LastPass\ F:\Temp\ 等等
rem 用SrcDir1=:D:\LastPass\ SrcDir2=F:\Temp\ 试了好象也不行 只能一个个来就正常了
set SrcDir=I:\Windows\TOP_2014\
rem 指定天数
set DaysAgo=6
>"%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" (
del /f /q "%%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"