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-06-24 14:54
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] How to display the remaining space of a disk? DigestI View 19,797 Replies 46
Floor 31 Posted 2006-06-11 18:54 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re namejm:

It's a pity there's no Win2000 environment, so I can't test. The targeted solution needs you to detail the error message.

Currently, the way I can think of is to remove find, and it works under CMD@WinXP:


@echo off & setlocal EnableDelayedExpansion
for %%d 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 %%d:\nul (
for /f "tokens=3" %%z in ('dir /-c %%d:\') do set freesize=%%z
set /a freesize=!freesize:~0,-3!/1049>nul
set freesize= !freesize!
set freesize=!freesize:~-9!
echo %%d drive free space:!freesize! MB
)
)
pause
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 32 Posted 2006-06-11 20:08 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
When using the method of intercepting the last few characters to right-align the display of the disk volume label name and remaining space, the following incorrect format occurs (it can be formatted correctly when the volume label name is all in English). What is the reason?

The code and picture are as follows

@echo off
cls
color 2e
title Situation of remaining space in each partition
echo.
echo.
echo ╔══════════════════════════════╗
echo ║ Disk partitions Disk volume label name Remaining space (MB) ║
echo ║ _____________________________________________________ ║
setlocal enabledelayedexpansion
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 2>nul
set freesize= !freesize!
set freesize=!freesize:~-7!
for /f "tokens=4" %%c in ('vol %%a:') do set volume=%%c
set volume= !volume!
set volume=!volume:~-20!
echo ║ %%a: !volume! !freesize! ║
)
)
)
echo ╚══════════════════════════════╝
pause>nul


[ Last edited by willsort on 2006-6-12 at 19:31 ]
Attachments
error1.jpg
Floor 33 Posted 2006-06-11 20:23 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re namejm:

Because NT internally uses Unicode encoding, and one characteristic of Unicode characters is that "English and Chinese characters with different display widths have the same byte length and character length".

This problem is relatively difficult to solve. The alternative solutions are nothing more than ensuring that no Chinese characters appear (that is, not displaying the volume label), or following my original suggestion of not using borders and moving the volume label column to the back.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 34 Posted 2006-06-11 21:03 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
It's really that you can't have both fish and bear's paws! :(
Floor 35 Posted 2006-06-12 19:27 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re: namejm:

Now, some schemes to align Chinese characters or other multi-byte characters are thought of.

If it can be ensured that the displayed variable string only has Chinese characters, when padding variables, blank Chinese characters (such as full-width spaces in full-width state) can be used instead of ordinary spaces;

Otherwise, it is necessary to judge the display width of the variable string. In the default Chinese environment, it can be understood as judging the byte length of the variable string in the local encoding (ANSI). Regarding this point, the current scheme is to generate a temporary file (using ANSI encoding by default), and determine the variable length according to the file length. The code is as follows

But it still cannot align the overly long volume labels of NTFS. So I still suggest not insisting on adopting certain special character arrangement methods. There are many alternative schemes. For example, the volume label can be written in the front, and the drive letter will be followed by a pair of parentheses immediately after the volume label, as shown in "My Computer".

And displaying changing strings in the border will always have the hidden danger of misaligned borders, and it also affects the readability of the code itself. Good typesetting effects can also be achieved by using other methods without using borders.

In addition, the volume of the picture attachment is too large, and only one is left for illustration; in addition, the screenshot of the CMD window using a 16-color GIF will be much smaller in size, and the effect will not be too distorted.

DrvSpace.cmd

@echo off & setlocal EnableDelayedExpansion
color 2e
title Disk Partition Free Space
echo.
echo.
echo ╔══════════════════════════════╗
echo ║ Disk Partitions Disk Volume Name Free Space(MB) ║
echo ║ _____________________________________________________ ║
for %%d 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 %%d:\nul (
for /f "tokens=3" %%z in ('dir /-c %%d:\') do set freesize=%%z
set /a freesize=!freesize:~0,-3!/1049>nul
set freesize= !freesize!
set freesize=!freesize:~-9!
for /f "tokens=3*" %%v in ('vol %%d:') do set volume=%%w
echo.!volume!>_volume.tmp
for %%f in (_volume.tmp) do for /l %%v in (%%~zf,1,20) do set volume= !volume!
echo ║ %%d: !volume! !freesize! ║
)
)
echo ╚══════════════════════════════╝
if exist _volume.tmp del _volume.tmp
pause


[ Last edited by willsort on 2006-6-12 at 19:34 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 36 Posted 2006-06-12 23:13 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Thanks to willsort, I have slightly modified the code and incorporated it into my file backup script. Although there are still potential risks, once it's published, more people will try to figure it out, which is better than doing nothing.

I just posted a few pictures and didn't notice the impact of image format and color quality on the image size. I will pay attention to posting pictures that are as small as possible but still relatively clear in the future.
Floor 37 Posted 2006-06-14 16:51 ·  中国 山西 太原 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline

───────────────── Moderation Record ─────────────────
Executor: Will Sort
Operation: Merge thread {21183} The formatting error occurred through the method of intercepting characters -> Posts 32~36
Description: The operated thread has a direct context connection with this thread
───────────────── Moderation Record ─────────────────
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 38 Posted 2006-09-19 08:41 ·  新加坡 腾讯云
初级用户
Credits 73
Posts 30
Joined 2006-09-18 08:35
19-year member
UID 62944
Status Offline
::View logicaldisk [Logical Disk] summary information.bat:
::---------BY MOBO in 2006-09-18
wmic logicaldisk list brief /format:hform >logicaldisk.htm
Floor 39 Posted 2006-09-19 08:56 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Han~~Nowadays, it's all about WMIC~~

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 40 Posted 2006-09-19 09:40 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Originally posted by electronixtar at 2006-9-19 08:56:
Cold~ Now it's all about WMIC~ ~

  Hehe, it seems that electronixtar is quite familiar with WMIC. I want to ask what are the advantages and disadvantages of WMIC and CMD respectively.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 41 Posted 2006-09-19 10:03 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
cmd is close to bat, while wmic is close to wbem, that's it~~

Actually, I don't know much about it~~ Just heard about it~~ BagPipe is an expert, but he doesn't post threads~~

Actually, Windows is becoming more and more like UNIX~~

[ Last edited by electronixtar on 2006-9-19 at 10:07 ]

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 42 Posted 2006-09-22 07:56 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
If you want to display the total size of the hard disk, how to write...
Floor 43 Posted 2007-01-21 10:26 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
If DOS supports floating-point operations, then the following method can be used to obtain disk space:


for /f "skip=4 tokens=4 delims=, " %%a in ('defrag c: -a') do (set /a freesize=%%a*1024)
pause

Unfortunately, an error is prompted because floating-point operations are not supported.
Floor 44 Posted 2007-01-21 10:43 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
Just now studied, modifying the above code can achieve a disguised floating-point calculation.

for /f "skip=4 tokens=4 delims=, " %%a in ('defrag d: -a') do echo %%a>ok.txt
for /f "tokens=1* delims=." %%a in (ok.txt) do set /a ok=%%a*1024+%%b*1024/100
echo %OK%
pause
Floor 45 Posted 2007-01-21 10:47 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,179
Posts 442
Joined 2006-09-09 22:47
19-year member
UID 62249
Status Offline
When modifying, I found that the FOR command actually supports calling variables as the SET set, so there's no need to generate temporary files anymore.


@echo off
set /p mydisk=Please enter the disk you want to query (such as E:):
for /f "skip=4 tokens=4 delims=, " %%a in ('defrag %mydisk% -a') do set dftemp=%%a
for /f "tokens=1* delims=." %%a in ("%dftemp%") do set /a diskfree=%%a*1024+%%b*1024/100
echo The remaining space of %mydisk% is: %diskfree%MB
pause


I'm sorry, I'm not very familiar with FOR and have been using it poorly all the time

[ Last edited by HUNRYBECKY on 2007-1-21 at 11:06 AM ]
Forum Jump: