首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > windows >

win2008自动剔除2天以前的文件夹

2013-09-28 
win2008自动删除2天以前的文件夹@echo beginecho Dont close this windows! echo Delete the file 2 days

win2008自动删除2天以前的文件夹
@echo begin
echo Dont close this windows! 
echo Delete the file 2 days ago and directory! 
@echo off&setlocal enabledelayedexpansion
echo set arg=wscript.arguments>temp.vbs
echo wscript.echo datediff("d",now(),arg(0))>>temp.vbs
for /f "delims=" %%i in ('dir /ad/b *') do (
for /f "delims=" %%a in ('cscript.exe /nologo "%~dp0temp.vbs" "%%~ti"') do set d=%%a
if !d! lss -2 (echo %%i&rd /s/q "%%i"))
del/q/f "%~dp0temp.vbs"
echo Delete OK! 

保存为BAT,双击执行没问题。
但是放在计划任务里就删除不了文件夹。


[解决办法]
test.bat

@echo off
echo Dont close this windows!
echo Delete the file 2 days ago and directory!
setlocal enabledelayedexpansion
echo set arg=wscript.arguments>"%temp%\temp.vbs"
echo wscript.echo datediff("d",now(),arg(0))>>"%temp%\temp.vbs"
for /f "delims=" %%i in ('dir /ad /b') do (
    for /f "delims=" %%a in ('cscript.exe /nologo "%temp%\temp.vbs" "%%~ti"') do (
        set d=%%a
    )
    if !d! lss -2 (
        echo %%i
        rd /s/q "%%i"
    )
)
echo Delete OK

热点排行