![]() |
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-10-24 04:10 |
47,815 topics / 349,928 posts / today 1 new / 48,287 members |
| DOS批处理 & 脚本技术(批处理室) » [Closed] How to display the remaining space of a disk? |
| Printable Version 22,253 / 46 |
| Floor16 namejm | Posted 2006-04-14 13:02 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
Originally posted by bagpipe at 2006-3-29 11:12: Can you tell me what method you used to implement it? I happen to need to test a batch script under Windows 2000. Thanks. [ Last edited by namejm on 2006-4-15 at 14:31 ] |
|
| Floor17 smileseeker | Posted 2006-04-14 17:15 |
| 中级用户 Posts 83 Credits 316 | |
|
for /f "tokens=3" %%a in ('"dir /-c c:\ | find "Available bytes""') do set freesize=%%a
This method is very good! |
|
| Floor18 chenhui530 | Posted 2006-04-15 21:41 |
| 高级用户 Posts 273 Credits 772 | |
|
Directly calling VBS should be much simpler
|
|
| Floor19 3742668 | Posted 2006-04-17 01:00 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
Actually, batch (bat) is actually much simpler than VBScript (vbs).
|
|
| Floor20 namejm | Posted 2006-04-17 18:17 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
Originally posted by 3742668 at 2006-4-17 01:00: Then if you want to query the remaining space size of all existing disk partitions, requiring to use MB as the unit, without relying on third-party software, how to write the code? Can this function be implemented under 2000? |
|
| Floor21 namejm | Posted 2006-04-21 19:43 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
In the XP environment, I want to query the remaining space of each partition and display it in MB. Why can't the following code get the correct result?
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:\nul ( for /f "tokens=3" %%b in ('dir /-c %%a:\^|find "Available bytes"') do set freesize=%%b set /a freesize=%freesize:~0,-3%/1049>nul echo %% a drive remaining space:%freesize% MB ) |
|
| Floor22 3742668 | Posted 2006-04-21 22:44 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
It is estimated that it is because you have not enabled delayed environment variables, resulting in the value of freesize not being considered as changed. It is suggested to use SETLOCAL ENABLEDELAYEDEXPANSION to enable delayed environment variables, and additionally use!freesize! to replace %freesize%. But since it's XP, why consider a one-command solution?
|
|
| Floor23 namejm | Posted 2006-04-22 13:03 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Because I want to display the remaining space of all existing partitions and display it in MB, so I need to use the for statement. I don't understand the use of SETLOCAL ENABLEDELAYEDEXPANSION very well. Specifically, what parts need to be modified? Can I modify it based on the code I posted? Thank you.
|
|
| Floor24 3742668 | Posted 2006-04-22 13:32 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
Just now I took a look, your code obviously lacks a ), so first you should add a ) at the end. Secondly, there is an extra space between echo %% a. Thirdly, the algorithm is problematic and the result may be incorrect. Finally, the usage of SETLOCAL ENABLEDELAYEDEXPANSION:
If you want to get the precise space number in MB, it's not impossible. As long as you change the division to subtraction and write your own code to calculate in two parts, of course, it's not very practical. In fact, it should be simpler to use wmic to save the remaining space numbers of each drive and then calculate the MB number through operations by yourself. |
|
| Floor25 chineselgs | Posted 2006-04-22 13:44 |
| 高级用户 Posts 266 Credits 613 From 河南省 | |
|
Can't understand it too much~~~~~~~~~~
|
|
| Floor26 namejm | Posted 2006-04-22 17:16 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
to 3742668:
Thank you for your patient answer, which solved a long-standing problem for me. Thanks again. "If you want to get the precise space number in megabytes, it's not impossible. As long as change the division to subtraction and write your own code in two parts to calculate, it's okay" ----Hehe, I didn't expect there is such a way of writing. Batch processing is really interesting. Can you post a code snippet to let me have a look? "Of course, not very practical." ----Do you mean that the approach of dividing into two code segments is not practical or that displaying in megabytes is not practical? If it's the latter, I don't quite agree with you. "Actually, using wmic can save the remaining space numbers of each disk, and then through calculation by yourself to get the megabyte number should be simpler." ----Will this generate temporary files? If temporary files are to be generated, it doesn't feel very perfect. [ Last edited by namejm on 2006-4-22 at 17:42 ] |
|
| Floor27 3742668 | Posted 2006-04-22 18:40 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
1. It's relatively troublesome to calculate. Let me talk about the idea. You can try it yourself:
Actually, it's just like doing division by hand, but divided into two parts. First, use the first 7 digits to calculate with 1048576, then combine the remaining part after subtraction with the combination of digits other than the first 7 digits and calculate with 1048576, and finally combine the results of the two parts. 2. The reason why it's said to have no practicality is that considering the execution speed and complexity, it's better to use other methods. 3. I think you didn't look carefully at that batch processing of the wmic result. You can look again to see whether the result is saved in a variable or in a file. |
|
| Floor28 namejm | Posted 2006-04-22 22:34 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
Originally posted by 3742668 at 2006-4-22 18:40: Hehe, it's not that I didn't look, but that I'm very unfamiliar with wmic and can't understand it. :( Still, thank you for your explanation. |
|
| Floor29 namejm | Posted 2006-04-22 22:47 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
In the 2000 system environment, the statement `for /f "tokens=3" %%b in ('dir /-c %%a:\^|find "可用字节"') do set freesize=%%b` always fails to get the correct result. How to modify the code?
|
|
| Floor30 namejm | Posted 2006-06-11 18:29 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Is there anyone who can answer the question on floor 29? I really want to know how to handle it.
|
|
| Prev 1 2 3 4 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |