![]() |
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-05 13:38 |
48,038 topics / 350,123 posts / today 1 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » Can the DOS command be used to obtain the remaining disk space? |
| Printable Version 3,074 / 20 |
| Floor1 acme | Posted 2007-04-11 20:42 |
| 中级用户 Posts 98 Credits 238 From 陕西 | |
|
Can DOS commands be used to obtain the remaining disk space?
Dear brothers: Can DOS do it? ; ) |
|
| Floor2 Climbing | Posted 2007-04-11 22:19 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
| Floor3 acme | Posted 2007-04-12 12:40 |
| 中级用户 Posts 98 Credits 238 From 陕西 | |
|
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?
|
|
| Floor4 lxmxn | Posted 2007-04-12 14:10 |
| 版主 Posts 4,938 Credits 11,386 | |
|
No. |
|
| Floor5 acme | Posted 2007-04-12 21:07 |
| 中级用户 Posts 98 Credits 238 From 陕西 | |
|
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!" |
|
| Floor6 Climbing | Posted 2007-04-12 21:31 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
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 |
|
| Floor7 bjsh | Posted 2007-04-12 22:57 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
wmic logicaldisk where deviceID="c:" get FreeSpace |more +1
Change the c: in it to other drives for other drives |
|
| Floor8 GOTOmsdos | Posted 2007-04-12 23:48 |
| 铂金会员 Posts 1,827 Credits 5,154 | |
|
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 |
|
| Floor9 airosp | Posted 2007-04-12 23:56 |
| 初级用户 Posts 41 Credits 99 | |
|
Using diskpart is also good~
|
|
| Floor10 acme | Posted 2007-04-13 08:49 |
| 中级用户 Posts 98 Credits 238 From 陕西 | |
|
Can you give a detailed explanation? How to use him in the conditional judgment? Thanks!
|
|
| Floor11 bjsh | Posted 2007-04-13 10:04 |
| 银牌会员 Posts 621 Credits 2,000 | |
|
for /f %%a in ('wmic logicaldisk where deviceID="c:" get FreeSpace ^|more +1') do if "%%a" geq ......
|
|
| Floor12 acme | Posted 2007-04-13 20:41 |
| 中级用户 Posts 98 Credits 238 From 陕西 | |
|
Thanks. If the verification is okay, I'll come back later to thank the guide.
|
|
| Floor13 acme | Posted 2007-04-17 08:56 |
| 中级用户 Posts 98 Credits 238 From 陕西 | |
|
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. |
|
| Floor14 acme | Posted 2007-04-17 20:57 |
| 中级用户 Posts 98 Credits 238 From 陕西 | |
|
Dude, please pay attention.
|
|
| Floor15 a25969805 | Posted 2007-04-24 23:09 |
| 新手上路 Posts 3 Credits 5 | |
|
@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 |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |