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-05 12:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Can the DOS command be used to obtain the remaining disk space? View 3,070 Replies 20
Original Poster Posted 2007-04-11 20:42 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 238
Posts 98
Joined 2007-04-10 07:50
19-year member
UID 84593
Gender Male
From 陕西
Status Offline
Can DOS commands be used to obtain the remaining disk space?
Dear brothers: Can DOS do it? ; )
Floor 2 Posted 2007-04-11 22:19 ·  中国 河北 保定 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2007-04-12 12:40 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 238
Posts 98
Joined 2007-04-10 07:50
19-year member
UID 84593
Gender Male
From 陕西
Status Offline
The remaining space size can be displayed with dir/c; but I want to use the remaining space size as a judgment condition. Can dir/c assign the value of the remaining size to =a? set a=%dir/c% Is that okay?
一切皆有可能!我行!我能!
Floor 4 Posted 2007-04-12 14:10 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

No.
Floor 5 Posted 2007-04-12 21:07 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 238
Posts 98
Joined 2007-04-10 07:50
19-year member
UID 84593
Gender Male
From 陕西
Status Offline
The purpose I mentioned is to achieve that when the free space on drive D is less than 500MB, delete the earliest 2GB of data created in drive D. Brothers, do you think it can be achieved through a *.bat?
"Don't laugh if the problem is naive, I'm a newbie!"
一切皆有可能!我行!我能!
Floor 6 Posted 2007-04-12 21:31 ·  中国 河北 保定 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Newcomers are not ridiculous, but it is not good if newbies keep asking questions without seriously studying previous discussion content.

Your question is not complicated and should be relatively easy to solve. I can suggest that you use the for command to extract relevant values for judgment, or use the wmic command:

wmic logicaldisk list brief
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
acme +1 2007-04-13 08:48
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 7 Posted 2007-04-12 22:57 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
wmic logicaldisk where deviceID="c:" get FreeSpace |more +1

Change the c: in it to other drives for other drives
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
acme +1 2007-04-13 08:48
Floor 8 Posted 2007-04-12 23:48 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
23-year member
UID 7105
Gender Male
Status Offline
If it is under pure DOS:
1
Use a third-party get K, but it seems to only support up to 2GB
2
Use a third-party LMOD, analyze the result of DIR, no 2GB limit
dir C:\ /w/ahd | find " free" | lmod /s set freesize=[$!-2] [$!-1][-]>freesize.bat
call freesize
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
acme +2 2007-04-13 08:47
Floor 9 Posted 2007-04-12 23:56 ·  中国 河北 石家庄 电信
初级用户
Credits 99
Posts 41
Joined 2007-02-19 03:42
19-year member
UID 79773
Gender Male
Status Offline
Using diskpart is also good~
量子公民
Floor 10 Posted 2007-04-13 08:49 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 238
Posts 98
Joined 2007-04-10 07:50
19-year member
UID 84593
Gender Male
From 陕西
Status Offline
Can you give a detailed explanation? How to use him in the conditional judgment? Thanks!
一切皆有可能!我行!我能!
Floor 11 Posted 2007-04-13 10:04 ·  中国 浙江 杭州 华数宽带
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
for /f %%a in ('wmic logicaldisk where deviceID="c:" get FreeSpace ^|more +1') do if "%%a" geq ......
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
acme +1 2007-04-17 20:57
Floor 12 Posted 2007-04-13 20:41 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 238
Posts 98
Joined 2007-04-10 07:50
19-year member
UID 84593
Gender Male
From 陕西
Status Offline
Thanks. If the verification is okay, I'll come back later to thank the guide.
一切皆有可能!我行!我能!
Floor 13 Posted 2007-04-17 08:56 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 238
Posts 98
Joined 2007-04-10 07:50
19-year member
UID 84593
Gender Male
From 陕西
Status Offline
I tried many things and none worked. Can any expert explain it in detail?
What I want to achieve is:
If the space on drive D is less than 1GB, automatically delete the 2 folders with the earliest creation time.
一切皆有可能!我行!我能!
Floor 14 Posted 2007-04-17 20:57 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 238
Posts 98
Joined 2007-04-10 07:50
19-year member
UID 84593
Gender Male
From 陕西
Status Offline
Dude, please pay attention.
一切皆有可能!我行!我能!
Floor 15 Posted 2007-04-24 23:09 ·  中国 福建 龙岩 电信
新手上路
Credits 5
Posts 3
Joined 2006-12-29 03:15
19-year member
UID 74878
Gender Male
Status Offline
@echo off
set driver=e
for /f "tokens=1-10 delims=, " %%a in ('dir %driver%: ^| find "Available bytes"') do set c=%%c
for /f "tokens=1-10 delims=, " %%a in ('dir %driver%: ^| find "Available bytes"') do set d=%%d
for /f "tokens=1-10 delims=, " %%a in ('dir %driver%: ^| find "Available bytes"') do set e=%%e
for /f "tokens=1-10 delims=, " %%a in ('dir %driver%: ^| find "Available bytes"') do set f=%%f
for /f "tokens=1-10 delims=, " %%a in ('dir %driver%: ^| find "Available bytes"') do set g=%%g
for /f "tokens=1-10 delims=, " %%a in ('dir %driver%: ^| find "Available bytes"') do set h=%%h
echo %d% | find "bytes" >nul
if %ERRORLEVEL% neq 0 goto nexte
set space=%c%
:nexte
echo %e% | find "bytes" >nul
if %ERRORLEVEL% neq 0 goto nextf
set space=%c%%d%
set /a space=%space%/1024/1024
:nextf
echo %f% | find "bytes" >nul
if %ERRORLEVEL% neq 0 goto nextg
set space=%c%%d%%e%
set /a space=%space%/1024/1024
:nextg
echo %g% | find "bytes" >nul
if %ERRORLEVEL% neq 0 goto nexth
set space=%d%%e%%f%
set /a space=%space%/1024/1024
set t=%c%
set /a t=%t%*953
set /a space=%space%+%t%
:nexth
echo %h% | find "bytes" >nul
if %ERRORLEVEL% neq 0 goto nextx
set space=%c%%d%%e%%f%%g%
set space=%d%%e%%f%
set /a space=%space%/1024/1024
set t=%c%%d%
set /a t=%t%*953
set /a space=%space%+%t%
:nextx
echo %driver%:=%space%M___FREE
echo Press any key to exit... && pause>nul
Forum Jump: