![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-23 12:56 |
47,812 topics / 349,917 posts / today 0 new / 48,273 members |
| DOS批处理 & 脚本技术(批处理室) » Help, detect folder capacity, when exceeding the limit, delete the file with the earliest date |
| Printable Version 10,904 / 0 |
| Floor1 snmm2004 | Posted 2021-05-04 16:43 |
| 初级用户 Posts 34 Credits 76 | |
|
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 ) |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |