bat 删除几天前的文件夹 还有点疑问
@echooff&setlocalenabledelayedexpansiontitle%date%%time:~,8%byescortmnmsetd=%date:~0,...
@echo off&setlocal enabledelayedexpansion
title %date% %time:~,8% by escortmnm
set d=%date:~0,10%
mshta vbscript:createobject("scripting.filesystemobject").opentextfile("temp.txt",2,true).write(dateadd("d",-5,"%d%"))(window.close)
for /f "tokens=1 delims= " %%i in (temp.txt) do set t1=%%i
for /f "delims= " %%i in ('dir /ad/b d:\xxx\????-??-??-??-??-??') do (
set t2=%%i
set t3=!t2:~0,10!
if !t3! lss !t1! rd /s/q "d:\xxx\%%i")
del /f temp.txt&pause
::Coded By escortmnm from vbs团队
这是个删除5天前d:\xxx\下格式为????-??-??-??-??-??的文件夹的bat,现在的问题是假如现在是7月17号,那么temp.txt读取出的日期为2010-7-12,在月份的前面少了个0,导致他会把所有的????-??-??-??-??-??文件夹 全部删掉,求大家给我个解决办法 展开
title %date% %time:~,8% by escortmnm
set d=%date:~0,10%
mshta vbscript:createobject("scripting.filesystemobject").opentextfile("temp.txt",2,true).write(dateadd("d",-5,"%d%"))(window.close)
for /f "tokens=1 delims= " %%i in (temp.txt) do set t1=%%i
for /f "delims= " %%i in ('dir /ad/b d:\xxx\????-??-??-??-??-??') do (
set t2=%%i
set t3=!t2:~0,10!
if !t3! lss !t1! rd /s/q "d:\xxx\%%i")
del /f temp.txt&pause
::Coded By escortmnm from vbs团队
这是个删除5天前d:\xxx\下格式为????-??-??-??-??-??的文件夹的bat,现在的问题是假如现在是7月17号,那么temp.txt读取出的日期为2010-7-12,在月份的前面少了个0,导致他会把所有的????-??-??-??-??-??文件夹 全部删掉,求大家给我个解决办法 展开
1个回答
展开全部
针对楼主的要求,对上述BAT修改如下:
@echo off&setlocal enabledelayedexpansion
title %date% %time:~,8% by escortmnm
set d=%date:~0,10%
mshta vbscript:createobject("scripting.filesystemobject").opentextfile("temp.txt",2,true).write(dateadd("d",-5,"%d%"))(window.close)
for /f "tokens=1-3 delims=-" %%i in (temp.txt) do (
set _t1=000%%i
set _t2=000%%j
set _t3=000%%k
set t1=!_t1:~-4!-!_t2:~-2!-!_t3:~-2!
)
for /f "delims= " %%i in ('dir /ad/b d:\xxx\????-??-??-??-??-??') do (
set t2=%%i
set t3=!t2:~0,10!
if !t3! lss !t1! rd /s/q "d:\xxx\%%i")
del /f temp.txt&pause
::Coded By escortmnm from vbs团队
在windows xp 测试通过
@echo off&setlocal enabledelayedexpansion
title %date% %time:~,8% by escortmnm
set d=%date:~0,10%
mshta vbscript:createobject("scripting.filesystemobject").opentextfile("temp.txt",2,true).write(dateadd("d",-5,"%d%"))(window.close)
for /f "tokens=1-3 delims=-" %%i in (temp.txt) do (
set _t1=000%%i
set _t2=000%%j
set _t3=000%%k
set t1=!_t1:~-4!-!_t2:~-2!-!_t3:~-2!
)
for /f "delims= " %%i in ('dir /ad/b d:\xxx\????-??-??-??-??-??') do (
set t2=%%i
set t3=!t2:~0,10!
if !t3! lss !t1! rd /s/q "d:\xxx\%%i")
del /f temp.txt&pause
::Coded By escortmnm from vbs团队
在windows xp 测试通过
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询