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-08-07 17:42
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question. A batch file for when disk space is full and files need to be deleted View 1,227 Replies 8
Original Poster Posted 2008-03-02 21:49 ·  中国 四川 成都 郫都区 电信
新手上路
Credits 14
Posts 6
Joined 2008-03-02 21:01
18-year member
UID 111890
Gender Male
Status Offline
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.
Floor 2 Posted 2008-03-02 23:25 ·  中国 四川 成都 郫都区 电信
新手上路
Credits 14
Posts 6
Joined 2008-03-02 21:01
18-year member
UID 111890
Gender Male
Status Offline
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.
Floor 3 Posted 2008-03-03 15:19 ·  中国 四川 成都 郫都区 电信
新手上路
Credits 14
Posts 6
Joined 2008-03-02 21:01
18-year member
UID 111890
Gender Male
Status Offline
Can someone help me out... This is urgent... Thanks.
Floor 4 Posted 2008-03-03 22:21 ·  中国 广西 百色 中移铁通
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
@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
Floor 5 Posted 2008-03-03 22:58 ·  中国 广西 百色 中移铁通
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
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
Floor 6 Posted 2008-03-04 00:14 ·  中国 四川 成都 郫都区 电信
新手上路
Credits 14
Posts 6
Joined 2008-03-02 21:01
18-year member
UID 111890
Gender Male
Status Offline
Thanks, then I'll go test it.
Floor 7 Posted 2008-03-04 00:22 ·  中国 四川 成都 郫都区 电信
新手上路
Credits 14
Posts 6
Joined 2008-03-02 21:01
18-year member
UID 111890
Gender Male
Status Offline
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.
Floor 8 Posted 2008-03-04 00:23 ·  中国 四川 成都 郫都区 电信
新手上路
Credits 14
Posts 6
Joined 2008-03-02 21:01
18-year member
UID 111890
Gender Male
Status Offline
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...
Floor 9 Posted 2008-03-04 22:42 ·  中国 北京 华为云
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Forum Jump: