![]() |
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-25 23:09 |
47,812 topics / 349,910 posts / today 0 new / 48,264 members |
| DOS批处理 & 脚本技术(批处理室) » [Closed] How to display the remaining space of a disk? |
| Printable Version 20,768 / 46 |
| Floor1 namejm | Posted 2006-03-26 00:19 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
The operating system is WinXP. I want to realize the function of displaying the remaining disk space without using third-party software. I've been lurking for several days and wrote the following code. Please help me.
@echo off rem There are problems rem rem 1、How to convert the number of bytes into a number in MB unit? rem rem 2、How to not generate temporary files? color 1f title Display remaining space on drive C del size.txt>nul 2>nul dir /-c c:\|find "Available bytes">size.txt for /f "tokens=3" %%a in (size.txt) do echo There is %%a bytes of remaining space on drive C del size.txt>nul 2>nul echo. echo. echo. echo Press any key to exit pause>nul Now a perfect solution has been found. Please see the code: Source: Find the exact value of the remaining space of all partitions (in MB unit) [ Last edited by namejm on 2007-3-11 at 02:26 PM ] |
|
| Floor2 Climbing | Posted 2006-03-26 01:08 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Use:
set /a freesize=%%a/1048576 To calculate MB, freesize will hold the number in MB units. The method without generating temporary files may be a bit crude. Try this: for /f "tokens=3" %%a in ('dir /-c c:\') do set /a freesize=%%a/1048576 Since the line you need is in the last line, although this seems a bit tedious, it does meet the need. |
|
| Floor3 3742668 | Posted 2006-03-26 12:06 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
@echo off
echo Drive Letter Free Space Partition Size wmic logicaldisk where caption="c:" get size,freespace,caption | findstr /v /i "caption" pause>nul |
|
| Floor4 Climbing | Posted 2006-03-26 14:27 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
What is wmic?
|
|
| Floor5 namejm | Posted 2006-03-26 15:56 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
试了一下,提示说找不到操作数,不知何故.
(Tried it, and it said "operand not found", don't know why.) |
|
| Floor6 willsort | Posted 2006-03-26 20:12 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
### Re Climbing:
The above is quoted from the XP Help and Support Center document ms-its:C:\WINDOWS\Help\WMIC.chm::/WMIC_Overview.htm ### Re namejm: Need to use find to filter out text lines that are not file sizes for /f "tokens=3" %%a in ('dir /-c c:\^|find "Available bytes"') do set /a freesize=%%a/1048576 |
|
| Floor7 Climbing | Posted 2006-03-26 20:34 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
Hmm, I’ve learned something.
|
|
| Floor8 namejm | Posted 2006-03-27 02:08 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
to willsort:
You need to use find to filter out text lines that are not file sizes for /f "tokens=3" %%a in ('dir /-c c:\^|find "Available bytes"') do set /a freesize=%%a/1048576 I tried running this code and used echo %freesize% to display the result, but it turned out to be a negative number, which was quite surprising. For example, my C drive is 2305712128 bytes, but the result showed -1897. Could it be that the CMD has gone crazy? |
|
| Floor9 willsort | Posted 2006-03-27 09:14 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re namejm:
CMD is not deranged, it's because the integer processed by set is too large. set stores integers in two bytes, with a 32-bit storage range limit, that is, its processing range is 2^-31~2^31-1, and your disk space exceeds this range and overflows. I don't have a very good solution for this, only an approximate algorithm of discarding the last three digits and then dividing by 1049. for /f "tokens=3" %%a in ('dir /-c c:\^|find "Available bytes"') do set freesize=%%a set /a freesize=%freesize:~0,-3%/1049>nul echo Freesize:%freesize% |
|
| Floor10 namejm | Posted 2006-03-27 17:58 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Thanks to the moderator's detailed explanation. It seems I can only use a somewhat approximate number.
|
|
| Floor11 bagpipe | Posted 2006-03-29 11:12 |
| 银牌会员 Posts 425 Credits 1,144 From 北京 | |
|
The `for /f "tokens=3" %%a in ('dir /-c c:\^|find "可用字节"') do set freesize=%%a` This sentence I can't execute, I don't know why I added the ^ leading character, please everyone test it. Mine is 2000, it didn't execute successfully, so I switched to other methods to get the result.........
|
|
| Floor12 3742668 | Posted 2006-03-29 11:24 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
XP, SP2 is normal.
Try for /f "tokens=3" %%a in ('"dir /-c c:\ | find "Available bytes""') do set freesize=%%a Use ^ to escape, otherwise it will execute dir /-c c:\ find "Available bytes" |
|
| Floor13 MIN | Posted 2006-03-29 11:41 |
| 初级用户 Posts 17 Credits 58 | |
|
Can you detect the remaining disk space under DOS?
|
|
| Floor14 namejm | Posted 2006-04-13 23:01 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Why can't the following method get the correct result when you want to query the remaining space size of all existing disk partitions?
for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do @( if exist %%a:\recycler\nul ( for /f "tokens=3" %%b in ('dir /-c %%a:\^|find "可用字节"') do set freesize=%%b set /a freesize=%freesize:~0,-3%/1049>nul echo %% a 盘剩余空间:%freesize% MB ) [ Last edited by namejm on 2006-4-14 at 12:59 ] |
|
| Floor15 DOSforever | Posted 2006-04-14 00:13 |
| 金牌会员 Posts 2,239 Credits 4,639 | |
Originally posted by MIN at 2006-3-29 11:41: Yes. See: How to detect the free space of a partition |
|
| 1 2 3 4 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |