中国DOS联盟论坛

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-08-07 16:58
48,041 topics / 350,128 posts / today 3 new / 48,252 members
DOS批处理 & 脚本技术(批处理室) » Question. A batch file for when disk space is full and files need to be deleted
Printable Version  1,225 / 8
Floor1 y111y Posted 2008-03-02 21:49
新手上路 Posts 6 Credits 14
Right now there is one server and N client machines. There is a situation now: because the client machines often automatically copy from the server to the local disk, drive D often runs out of space, and files have to be cleared manually.

So I'd like to ask: if I want to add a batch file when starting the computer, how should I do it?

The idea is as follows.

Automatically detect whether the free space on drive D is less than 8G
freedisk/d d: 8gb >null

If it is less than 8G, then delete the specified folders.
For example, folders 1 2 3 4 5. Maybe 1 was already deleted last time, so then delete them one by one in order, and check whether the disk space stays above 8G.
Floor2 y111y Posted 2008-03-02 23:25
新手上路 Posts 6 Credits 14
I'm an idiot, I only know a little bit of the simple stuff. Once it comes to loops I have no idea what I'm doing.
Floor3 y111y Posted 2008-03-03 15:19
新手上路 Posts 6 Credits 14
Can someone help me out... This is urgent... Thanks.
Floor4 moniuming Posted 2008-03-03 22:21
银牌会员 Posts 574 Credits 1,335 From 广西
@echo off
for %%a in (1 2 3 4 5) do (
for /f "tokens=3 delims= " %%b in ('dir d:\^|findstr "bytes free"') do (
if %%b lss 8000000000 (
echo rd /s /q "%%a"
) else (
goto out
)
)
)
:out
exit
Floor5 moniuming Posted 2008-03-03 22:58
银牌会员 Posts 574 Credits 1,335 From 广西
Ugh, after testing, the code from the poster above gives the error message "else is not expected at this time". The code below has already been fixed.
If the free space is greater than 8G, then the folder will not be deleted.
@echo off
for %%a in (1 2 3 4 5) do (
for /f "tokens=3 delims= " %%b in ('dir d:\^|findstr "free bytes"') do (
if %%b lss 8000000000 rd /s /q "d:\%%a"
if %%b gtr 8000000000 echo Disk space is already greater than 8G&goto out
)
)
:out
echo.&pause&exit /b
Floor6 y111y Posted 2008-03-04 00:14
新手上路 Posts 6 Credits 14
Thanks, then I'll go test it.
Floor7 y111y Posted 2008-03-04 00:22
新手上路 Posts 6 Credits 14
I'm a pig... Someone make a ready-made one for me... I'm a pig...
For example:
Keep disk space above 8GB... When it is below 8GB, delete D:\netgame\征途
Loop and check disk space. If the 征途 directory is already gone and the disk space is still greater than 8GB, then delete other specified folders. Loop through 10 folders.
Floor8 y111y Posted 2008-03-04 00:23
新手上路 Posts 6 Credits 14
I realized my learning is just pig-level, I only know things one at a time. When it comes to loops, I'm a complete mess of a pig...
Floor9 moniuming Posted 2008-03-04 22:42
银牌会员 Posts 574 Credits 1,335 From 广西
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023