China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-20 19:23
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help, detect folder capacity, when exceeding the limit, delete the file with the earliest date View 10,533 Replies 0
Original Poster Posted 2021-05-04 16:43 ·  中国 浙江 宁波 电信
初级用户
Credits 76
Posts 34
Joined 2008-05-10 16:18
18-year member
UID 118340
Gender Male
Status Offline
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
)
Forum Jump: