|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 31 楼』:
使用 LLM 解释/回答一下
Re namejm:
可惜没有Win2000的环境,无法测试,对症的解法需要你详细说明错误信息。
目前,我能想到的办法就是取消find,在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 盘剩余空间:!freesize! MB
)
)
pause
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-6-11 18:54 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 32 楼』:
通过截取字符的方法排版出现错误
使用 LLM 解释/回答一下
通过截取字符最后几位的方法右对齐显示磁盘卷标名和剩余空间的时候,发生了如下的错误格式(当卷标名全为英文的时候能正确排版),请问是何原因?
代码和图片如下
@echo off
cls
color 2e
title 各分区剩余空间情况
echo.
echo.
echo ╔══════════════════════════════╗
echo ║ 磁盘分区 磁盘卷标名 剩余空间(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 "可用字节"') 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 ]
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 ]
附件
1: error1.jpg (2006-6-11 20:08, 37.38 KiB, 下载附件所需积分 1 点
,下载次数: 2)
|
|
2006-6-11 20:08 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 33 楼』:
使用 LLM 解释/回答一下
Re namejm:
因为NT内部采用Unicode编码,而Unicode字符有一个特点——“不同显示宽度的英文和中文字符,有相同的字节长度和字符长度”。
这个问题解决起来比较困难。替代的方案无非就是保证不出现中文(也即不显示卷标),或者依照我原来的建议不使用边框并将卷标列移到后方。
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-6-11 20:23 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 34 楼』:
使用 LLM 解释/回答一下
真是鱼和熊掌不可兼得啊:(
It's really that you can't have both fish and bear's paws! :(
|
|
2006-6-11 21:03 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 35 楼』:
使用 LLM 解释/回答一下
Re namejm:
现在,想到一些方案来对齐汉字或其它多字节字符了。
如果可以确保显示的变量串只有汉字,则补齐变量时可以用空白的汉字(比如全角状态下的空格)来代替普通的空格;
否则,需要判断变量串的显示宽度,在缺省的中文环境下,可以理解为判断本地编码(ANSI)的变量串的字节长度,关于此点,现在的方案是生成临时文件(缺省采用ANSI编码),根据文件长度确定变量长度。代码如下
但是,它仍然无法对NTFS超长的卷标进行对齐。所以我仍然建议,不要强求去采用某些特殊的字符排列方式。可以代替的方案有很多,比如,卷标可以写在前面,而盘符将加上一对圆括弧紧跟在卷标后,如我的电脑中显示的那样。
而在边框中显示变化字符串,将始终潜伏着边框不对齐的隐患,而且它也影响了代码本身的阅读性,而不使用边框用其它方法也可以取得良好的排版效果。
另外,图片附件体积过大,只留一个就以示意;另外,CMD窗口的截图采用16的GIF体积会小很多,效果也不会太失真。
DrvSpace.cmd
@echo off & setlocal EnableDelayedExpansion
color 2e
title 各分区剩余空间情况
echo.
echo.
echo ╔══════════════════════════════╗
echo ║ 磁盘分区 磁盘卷标名 剩余空间(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 ]
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-6-12 19:27 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 36 楼』:
使用 LLM 解释/回答一下
感谢willsort,已经将代码稍加修改放进我的文件备份器脚本中去了。尽管还有潜在的风险,但是发出来之后,就会有更多的人来想办法,总比什么也不做强一点。
刚发了几张图片,没注意到图片格式和颜色质量对图片大小的影响,以后我会注意发那些尽可能小而又比较清晰的图片上来。
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.
|
|
2006-6-12 23:13 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 37 楼』:
使用 LLM 解释/回答一下
───────────────── 版务记录 ─────────────────
执行:Will Sort
操作:合并主题 {21183}通过截取字符的方法排版出现错误 -> 32~36 楼
说明:操作主题与本主题存在上下文的直接联系
───────────────── 版务记录 ─────────────────
───────────────── 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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-6-14 16:51 |
|
|
mobo
初级用户
 
积分 73
发帖 30
注册 2006-9-18
状态 离线
|
『第 38 楼』:
查看logicaldisk[逻辑盘]摘要信息
使用 LLM 解释/回答一下
::查看logicaldisk[逻辑盘]摘要信息.bat:
::---------BY MOBO in 2006-09-18
wmic logicaldisk list brief /format:hform >logicaldisk.htm
::View logicaldisk summary information.bat:
::---------BY MOBO in 2006-09-18
wmic logicaldisk list brief /format:hform >logicaldisk.htm
|
|
2006-9-19 08:41 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 39 楼』:
使用 LLM 解释/回答一下
寒~~现在动不动都WMIC的~~
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'>" |
|
2006-9-19 08:56 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 40 楼』:
使用 LLM 解释/回答一下
Originally posted by electronixtar at 2006-9-19 08:56:
寒~~现在动不动都WMIC的~~
呵呵,看来electronixtar对WMIC比较了解,想请教一下WMIC和CMD各有什么优劣。
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没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-19 09:40 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 41 楼』:
使用 LLM 解释/回答一下
cmd亲近bat而wmic亲近wbem,没了~~
其实了解也不多~~听说过而已~~BagPipe是专家,不过又不发帖~~
其实Windows越来越有UNIX的味道了~~
Last edited by electronixtar on 2006-9-19 at 10:07 ]
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'>" |
|
2006-9-19 10:03 |
|
|
zouzhxi
中级用户
   蝴蝶之吻
积分 430
发帖 177
注册 2006-9-20 来自 广东深圳
状态 离线
|
『第 42 楼』:
使用 LLM 解释/回答一下
Originally posted by willsort at 2006-6-11 18:54:
Re namejm:
可惜没有Win2000的环境,无法测试,对症的解法需要你详细说明错误信息。
目前,我能想到的办法就是取消find,在CMD@WinXP下测试栮..
如果是要显示硬盘总大小呢 怎么写....
If you want to display the total size of the hard disk, how to write...
|

Butterfly Kiss Blog
计算机DIY联盟论坛 |
|
2006-9-22 07:56 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 43 楼』:
使用 LLM 解释/回答一下
如果DOS支持浮点运算的话,那么获取磁盘空间还可以使用如下方法:
for /f "skip=4 tokens=4 delims=, " %%a in ('defrag c: -a') do (set /a freesize=%%a*1024)
pause
可惜的是提示错误,原因是不支持浮点运算。
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.
|
|
2007-1-21 10:26 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 44 楼』:
使用 LLM 解释/回答一下
刚才研究了下,修改了上面的代码就可以实现变相的浮点预算了。
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
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
|
|
2007-1-21 10:43 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 45 楼』:
使用 LLM 解释/回答一下
在修改下,发现FOR命令居然支持调用变量作为SET集,这下不用产生临时文件了。
@echo off
set /p mydisk=请你输入要查询的磁盘(如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 %mydisk%的剩余空间为:%diskfree%MB
pause
不好意思,对FOR不是很熟悉,一直用不好
Last edited by HUNRYBECKY on 2007-1-21 at 11:06 AM ]
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 ]
|
|
2007-1-21 10:47 |
|