|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
Originally posted by bagpipe at 2006-3-29 11:12:
for /f "tokens=3" %%a in ('dir /-c c:\^|find "可用字节"') do set freesize=%%a这句我执行不了,不知道为什么加个^前导字符,请各位试验下,我的是2000,没有执行成功,所以改用其他方法得到结果.........
能不能说一下你用什么方法实现的,我正好需要在2000下测试个批处理.谢谢.
Last edited by namejm on 2006-4-15 at 14:31 ]
Originally posted by bagpipe at 2006-3-29 11:12:
The line "for /f "tokens=3" %%a in ('dir /-c c:\^|find "可用字节"') do set freesize=%%a" doesn't work for me. I don't know why there's a ^ prefix. Please test it. I'm on Windows 2000 and it didn't work, so I used other methods to get the result...
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 ]
|
|
2006-4-14 13:02 |
|
|
smileseeker
中级用户
  
积分 316
发帖 83
注册 2005-3-1
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
for /f "tokens=3" %%a in ('"dir /-c c:\ | find "可用字节""') do set freesize=%%a
这个 方法很好啊
for /f "tokens=3" %%a in ('"dir /-c c:\ | find "Available bytes""') do set freesize=%%a
This method is very good!
|
|
2006-4-14 17:15 |
|
|
chenhui530
高级用户
   
积分 772
发帖 273
注册 2004-10-23
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
直接调用VBS应该简单的多
Directly calling VBS should be much simpler
|

http://www.msfans.net/bbs/ |
|
2006-4-15 21:41 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
其实应该是bat比vbs简单得多。
Actually, batch (bat) is actually much simpler than VBScript (vbs).
|
|
2006-4-17 01:00 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
Originally posted by 3742668 at 2006-4-17 01:00:
其实应该是bat比vbs简单得多。
那如果想查询所有存在的磁盘分区的剩余空间大小,要求用MB为单位,不借助第三方软件,该如何写代码呢?
在2000下能实现这个功能吗?
Originally posted by 3742668 at 2006-4-17 01:00:
Actually, bat is much simpler than vbs.
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?
|
|
2006-4-17 18:17 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
在XP环境下,想查询每个分区的剩余空间,以MB为单位显示,以下代码为什么不能得出正确结果呢?
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
echo %% a 盘剩余空间:%freesize% MB
)
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
)
|
|
2006-4-21 19:43 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
估计是因为你没有启用延迟环境变量的缘故,导致freesize的值以为未变。建议用SETLOCAL ENABLEDELAYEDEXPANSION来启用延迟环境变量,另外需用!freesize!来替代%freesize%。不过既然是XP,何必考虑一个命令搞定呢?
@echo off
for /f "tokens=1,2" %%i in ('"wmic logicaldisk get freespace,caption"') do set %%i=%%j
echo C盘剩余空间为: %c:% 字节
echo D盘剩余空间为: %d:% 字节
echo E盘剩余空间为: %e:% 字节
pause
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?
@echo off
for /f "tokens=1,2" %%i in ('"wmic logicaldisk get freespace,caption"') do set %%i=%%j
echo The free space of drive C is: %c:% bytes
echo The free space of drive D is: %d:% bytes
echo The free space of drive E is: %e:% bytes
pause
|
|
2006-4-21 22:44 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
Originally posted by 3742668 at 2006-4-21 22:44:
估计是因为你没有启用延迟环境变量的缘故,导致freesize的值以为未变。建议用SETLOCAL ENABLEDELAYEDEXPANSION来启用延迟环境变量,另外需用!freesize!来替代% ...
因为想显示 所有存在的分区的剩余空间,并且要 以MB为单位显示,所以要用到for语句,对SETLOCAL ENABLEDELAYEDEXPANSION的使用不是很了解,具体要修改什么地方,能不能在我贴出来的代码基础上进行修改呢?谢谢.
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.
|
|
2006-4-22 13:03 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
刚才看了一下,你的代码明显差个),所以首先应该在最后加个)
其次,echo %% a 中间多了个空格。
再次,算法有问题,结果可能出现错误。
最后,SETLOCAL ENABLEDELAYEDEXPANSION的用法:
@echo off
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
echo %%a 盘剩余空间:!freesize! MB
)
)
pause
如果想得到精确的以mb为单位的空间数也不是没有办法,只要把除法改成减法自己写代码分两部分算就行了,当然,没什么实用性。
其实利用wmic可以保存各个盘的剩余空间数,然后自己再通过运算来获得mb数应该简单一些。
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:
@echo off
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
echo %%a drive free space:!freesize! MB
)
)
pause
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.
|
|
2006-4-22 13:32 |
|
|
chineselgs
高级用户
    论坛灌水专业户
积分 613
发帖 266
注册 2006-4-19 来自 河南省
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
看不太懂~~~~~~~~~~
Can't understand it too much~~~~~~~~~~
|
|
2006-4-22 13:44 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 26 楼』:
使用 LLM 解释/回答一下
to 3742668:
感谢你的耐心回答,解决了一个困扰我很久的难题,再次感谢.
"如果想得到精确的以mb为单位的空间数也不是没有办法,只要把除法改成减法自己写代码分两部分算就行了"
----呵呵,想不到还有这样的写法,批处理真是太有趣了,能不能贴段代码出来开开眼界呢?
"当然,没什么实用性。"
----你是说分成两段代码的做法没实用性还是说以MB为单位显示没实用性呢?如果是后者的话,我可不太同意你的说法.
"其实利用wmic可以保存各个盘的剩余空间数,然后自己再通过运算来获得mb数应该简单一些。"
----这样做会产生临时文件吗?如果要产生临时文件的话,感觉还不是很完美.
Last edited by namejm on 2006-4-22 at 17:42 ]
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 ]
|
|
2006-4-22 17:16 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 27 楼』:
使用 LLM 解释/回答一下
1.算起来比较麻烦,把思路说一下你自己尝试了看吧:
其实就是按照手算除法一样,不过分成两部分,先用前7位与1048576计算,然后把减剩下的加前7位以外的组合了再与1048576计算,最后把两部分的结果合并起来就行了。
2,之所以说没有什么实用性,因为考虑到执行速度以及繁琐程度,不如改用其它的方法。
3,我想你没有仔细去看那个wmic结果的批处理,你仔细再看看结果是保存在变量中还是保存在文件中。。
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.
|
|
2006-4-22 18:40 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
Originally posted by 3742668 at 2006-4-22 18:40:
3,我想你没有仔细去看那个wmic结果的批处理,你仔细再看看结果是保存在变量中还是保存在文件中。。
呵呵,不是我没看,是我对wmic很陌生,看不懂:(
还是谢谢你的解答.
Originally posted by 3742668 at 2006-4-22 18:40:
3, I think you didn't look at that batch processing of the wmic result carefully. You can take another look to see whether the result is saved in a variable or in a file.
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.
|
|
2006-4-22 22:34 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 29 楼』:
使用 LLM 解释/回答一下
在2000系统环境中,for /f "tokens=3" %%b in ('dir /-c %%a:\^|find "可用字节"') do set freesize=%%b这句始终不能得到正确结果,请问该如何修改代码?
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?
|
|
2006-4-22 22:47 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
29楼的问题有人解答吗?很想知道该怎么处理。
Is there anyone who can answer the question on floor 29? I really want to know how to handle it.
|
|
2006-6-11 18:29 |
|