检测文件夹容量,当超限时,删除日期最早的文件直到下限为止
网上下载的(
https://zhidao.baidu.com/question/535778787.html)win7可以运行win10运行不了,请高手帮忙看看,哪里出问题了,非常感谢
@echo off
setlocal enabledelayedexpansion
set /a f=1536*1
set /a z=2048*1
set id=1
set "sp=d:\back\"
del /f /q /a list$ >nul 2>nul
>tmp.vbs echo result = wscript.arguments(0)/1024/1024
>>tmp.vbs echo Wscript.Echo int(result)
:loop
if exist !sp! (
for /f "tokens=3" %%j in ('dir /-c /s !sp!^|find "个文件"') do set num=%%j
if not "%%j"=="0" (
for /f "delims=" %%a in ('cscript //nologo tmp.vbs !num!') do (
if %%a gtr !z! set free=A
if %%a leq !f! set free=
)))
if defined free (
if not exist "list$" (
echo 查询于%date:~0,10%-%time:~0,8%>list$
for /f "tokens=1-3*" %%i in ('dir /a-d /tc /s /od !sp!^|findstr ":"') do (
set var=%%i%%j%%k%%l
if "!var:~1,1!"==":" set route=!var!
if not "!route!"=="!var!" if not "%%j"=="" echo %%i;!route:~0,-3!\%%l>>list$
))
call :delfile !id!
set /a id+=1
)
if defined free goto :loop
endlocal
del list$ >nul 2>nul&del tmp.vbs&echo 处理完成...&pause&exit /b
:delfile
for /f "skip=%1 tokens=2 delims=;" %%y in (list$) do (
echo 删除文件有风险,所以这是演示版,正式使用请删除本行及下一行及下两行开头的echo
echo 演示因为并未删除文件所以会导致无限循环假死,当屏幕不动时,可按CTRL+C退出.
echo del /a /q /f "%%y"
echo 按创建日期从先到后的排序删除了%%y文件...
goto :eof
)
Detect folder capacity, and when it exceeds the limit, delete the oldest files until it reaches the lower limit
Downloaded from the Internet (
https://zhidao.baidu.com/question/535778787.html), it can run on Win7 but not on Win10. Please help experts to see where the problem is, thank you very much
@echo off
setlocal enabledelayedexpansion
set /a f=1536*1
set /a z=2048*1
set id=1
set "sp=d:\back\"
del /f /q /a list$ >nul 2>nul
>tmp.vbs echo result = wscript.arguments(0)/1024/1024
>>tmp.vbs echo Wscript.Echo int(result)
:loop
if exist !sp! (
for /f "tokens=3" %%j in ('dir /-c /s !sp!^|find "个文件"') do set num=%%j
if not "%%j"=="0" (
for /f "delims=" %%a in ('cscript //nologo tmp.vbs !num!') do (
if %%a gtr !z! set free=A
if %%a leq !f! set free=
)))
if defined free (
if not exist "list$" (
echo Query at %date:~0,10%-%time:~0,8%>list$
for /f "tokens=1-3*" %%i in ('dir /a-d /tc /s /od !sp!^|findstr ":"') do (
set var=%%i%%j%%k%%l
if "!var:~1,1!"==":" set route=!var!
if not "!route!"=="!var!" if not "%%j"=="" echo %%i;!route:~0,-3!\%%l>>list$
))
call :delfile !id!
set /a id+=1
)
if defined free goto :loop
endlocal
del list$ >nul 2>nul&del tmp.vbs&echo Processing completed...&pause&exit /b
:delfile
for /f "skip=%1 tokens=2 delims=;" %%y in (list$) do (
echo Deleting files is risky, so this is a demo version. Please delete this line and the next line and the first two lines of the next line for formal use
echo The demo will cause infinite loop and freeze because it does not actually delete files. When the screen is not moving, you can press CTRL+C to exit.
echo del /a /q /f "%%y"
echo Deleted file %%y sorted by creation date from earliest...
goto :eof
)