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
)
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
)
