|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『楼 主』:
[挑战6]:硬盘容量的计算。难度[☆☆☆]
使用 LLM 解释/回答一下
呵呵,这一期的挑战系列没有准时在周一出现,请大家原谅(因工作繁忙,跟着几位大侠级
的人物学习调试设备,没有时间啊)
好了,该扯的也扯了,下面进入正题(硬盘容量的计算)
现在有 一 个硬盘,但我们不知道这个硬盘分了几个区,每个区的容量是多大,剩余
空间又几何。
假设这个硬盘的空间为:300G ,按照硬盘厂商的划分标准就是:
300*1000*1000*1000 的容量。
硬盘分为 4 个区,其中
盘符 总容量 剩余容量
-------------------------------------------------------------------------------
C: 20*1024*1024*1024 1000*1024*1024
D: 40*1024*1024*1024 30*1024*1024*1024
E: 80*1024*1024*1024 60*1024*1024*1024
剩余的为 F: 盘 我们已经知道 F:已经使用了 20*1024*1024*1024 的容量。。
-------------------------------------------------------------------------------
那么现在的问题是:F: 的实际容量是多大?
要求:将上述文件存为: Drivers.txt
从文件中读取这个 硬盘容量的文件,并进行计算。
对容量的计算要求采用 4 舍 5 入的法则,基本单位为M ,不足 1G 的计算剩余容量的实际
大小(精确到 M ),过 1G 的单位为 G ,但要求精确到小数点后三位。
程序使用要求:CMD(可以使用第三方工具,可以结合vbs来做,也可以单独使用vbs来完成)
采用了第三方工具完成目标的(积分为:2分)
完全独立使用cmd完成的(积分为:5分,满分)
难点:提取出正确容量的朋友:1分
正确使用除法运算的朋友,1分
精确单位使用良好的:1分
获取F盘正确容量的 2分。
Drivers.txt
-------------------------------------------------------------------------------
C: 20*1024*1024*1024 1000*1024*1024
D: 40*1024*1024*1024 30*1024*1024*1024
E: 80*1024*1024*1024 60*1024*1024*1024
F: ????? (???-20*1024*1024*1024)
-------------------------------------------------------------------------------
set "Volume_C=" ;精确到字节
set "Volume_D="
set "Volume_E="
set "Volume_F="
set "Real_Volume_C=" 精确到M or G
Dividend:被除数
Divisor:除数
Quotient:商
好了,下面就开始做题了。。
要求输出
C: %Volume_C%(%Real_Volume_C% ) 此处的M or G 只能存在一个。
d: %Volume_D%(%Real_Volume_D% )
e: %Volume_E%(%Real_Volume_E% )
f: %Volume_F%(%Real_Volume_F% )
输出:
例如: c: 1048576(1000M)
d: 32212254720(30G)
小于1G容量的用 M 做单位
大于1G容量的用 G 做单位
Last edited by flyinspace on 2007-5-9 at 01:23 PM ]
Hehe, this issue of the challenge series didn't appear on Monday on time, please forgive me (because of being busy with work and learning to debug equipment with a few expert-level people, I didn't have time).
Okay, enough chit-chat, let's get to the main topic now (calculation of hard disk capacity).
Now there is a hard disk, but we don't know how many partitions it has, the capacity of each partition, and the remaining space.
Suppose the space of this hard disk is: 300G, according to the division standard of the hard disk manufacturer, it is:
300*1000*1000*1000 in capacity.
The hard disk is divided into 4 partitions, among which
Drive letter Total capacity Remaining capacity
-------------------------------------------------------------------------------
C: 20*1024*1024*1024 1000*1024*1024
D: 40*1024*1024*1024 30*1024*1024*1024
E: 80*1024*1024*1024 60*1024*1024*1024
The remaining is drive F: We already know that 20*1024*1024*1024 of capacity has been used for drive F:.
-------------------------------------------------------------------------------
So now the question is: What is the actual capacity of drive F:?
Requirement: Save the above file as: Drivers.txt
Read this hard disk capacity file from the file and perform the calculation.
For the calculation of capacity, the rule of rounding is adopted. The basic unit is M. For the remaining capacity less than 1G, calculate the actual size (accurate to M). For the unit over 1G, it is G, but it is required to be accurate to three decimal places.
Program usage requirements: CMD (third-party tools can be used, can be combined with vbs, or can be completed alone with vbs)
For those who use third-party tools to complete the goal (points: 2 points)
For those who use CMD completely to complete (points: 5 points, full score)
Difficulty: Friends who extract the correct capacity: 1 point
Friends who use the division operation correctly: 1 point
Friends who use the accurate unit well: 1 point
Friends who get the correct capacity of drive F: 2 points.
Drivers.txt
-------------------------------------------------------------------------------
C: 20*1024*1024*1024 1000*1024*1024
D: 40*1024*1024*1024 30*1024*1024*1024
E: 80*1024*1024*1024 60*1024*1024*1024
F: ????? (???-20*1024*1024*1024)
-------------------------------------------------------------------------------
set "Volume_C=" ; accurate to bytes
set "Volume_D="
set "Volume_E="
set "Volume_F="
set "Real_Volume_C=" accurate to M or G
Dividend: dividend
Divisor: divisor
Quotient: quotient
Okay, let's start doing the problem now.
Requirement to output
C: %Volume_C%(%Real_Volume_C% ) Here M or G can only exist one.
d: %Volume_D%(%Real_Volume_D% )
e: %Volume_E%(%Real_Volume_E% )
f: %Volume_F%(%Real_Volume_F% )
Output:
For example: c: 1048576(1000M)
d: 32212254720(30G)
Use M as the unit for capacity less than 1G
Use G as the unit for capacity greater than 1G
Last edited by flyinspace on 2007-5-9 at 01:23 PM ]
|

知,不觉多。不知,乃求知 |
|
2007-5-8 23:04 |
|
|
dikex
高级用户
    潜水修练批处理
积分 788
发帖 366
注册 2006-12-31
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
取得系统所有分区的空间(单位:字节)可以使用下面的代码,至于精确的计算超大数字太麻烦了,留待下一位-_-
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "skip=1 delims=" %%i in ('fsutil fsinfo drives ^| more') do (
set a=%%i
for /f "skip=1 delims=" %%a in ('wmic LOGICALDISK where Caption^="!a:~-3,-1!" get size') do echo !a:~-3,-2! %%a
)
pause
Last edited by dikex on 2007-5-9 at 12:36 AM ]
To obtain the space of all partitions in the system (in bytes), you can use the following code. As for precisely calculating extremely large numbers, it's too cumbersome, and it's left to the next person -_-
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "skip=1 delims=" %%i in ('fsutil fsinfo drives ^| more') do (
set a=%%i
for /f "skip=1 delims=" %%a in ('wmic LOGICALDISK where Caption^="!a:~-3,-1!" get size') do echo !a:~-3,-2! %%a
)
pause
Last edited by dikex on 2007-5-9 at 12:36 AM ]
|

正在潜水修练的批处理小白 |
|
2007-5-9 00:13 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
楼上似乎理解错了楼主的意思了.
1F的题目看起来象计算题多点.
而不是查询硬盘的.
It seems that the person above has misunderstood the LZ's meaning.
The question in 1F looks more like a calculation problem.
Rather than querying the hard disk.
|
|
2007-5-9 09:46 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
你要标明是什么文件系统,这对计算最后可用空间的精度有影响
You need to indicate what file system it is, as it affects the accuracy of the final available space calculation.
|
|
2007-5-9 09:50 |
|
|
zhoushijay
高级用户
    Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
这道题对什么文件系统有关系吗?纯粹的数字乘乘除除而已。
难点在于读取文本啊,用P处理相对好读点,但是数值太大无法计算
用VBS可以计算但读取有点困难。
Does this problem have anything to do with the file system? It's just pure multiplication and division of numbers. The difficulty lies in reading the text. It's relatively easier to read with P, but the value is too large to calculate. VBS can be used for calculation but has some difficulties in reading.
|
|
2007-5-9 11:54 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
To youxi01:
主要是查询硬盘的容量(表面上是有了大数运算,但在这里,是可以通过一系列的方法避过的。)
To everest79:
兄想太多了,只是为了考察综合能力(若是真的不取巧的话,里面的内容是包含了加减乘除取余运算的)
那么在这里,就会涉及到子程序的调用问题,因为大量的四则运算若还是把加减乘除运算放在一起的话,代码的长度不敢想象:)
代码写得漂亮的,flyinspace在此另外加 3 分(难点在:合理搭配上,不需要每一句话的注释,但需要在子程序前标明这个子程序是做什么用的,刚用c++写了一个四则运算的小程序,正好来调用这每一个子程序,并看是否正确。)
ps:现在越来越感觉到算法的重要性了。大家在写这个脚本的时候,可以去网上,推荐CSDN查找大数运算的帖子。
To youxi01:
Mainly to query the capacity of the hard disk (apparently there are large number operations, but here, a series of methods can be used to bypass it.)
To everest79:
Brother, you're overthinking. It's just to test comprehensive ability (if you really don't take shortcuts, the content includes addition, subtraction, multiplication, division, and remainder operations.)
Then here, the issue of subroutine calls will be involved, because if a large number of four arithmetic operations are still put together, the length of the code is unimaginable : )
Those with beautiful code, flyinspace will additionally add 3 points here (the difficulty is: reasonable matching, no need to comment every sentence, but need to mark what this subroutine is for in front of the subroutine. Just wrote a small four arithmetic operation program in C++, which is just to call each subroutine and see if it is correct.)
ps: Now I'm increasingly feeling the importance of algorithms. Everyone can go to the Internet when writing this script, and it is recommended to find posts about large number operations on CSDN.
|

知,不觉多。不知,乃求知 |
|
2007-5-9 12:23 |
|
|
zhoushijay
高级用户
    Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
我插一句,省略了读取文本。呵呵
只是有些不太理解LZ题目的意思。。。
'C盘
uscb=20*1024*1024*1024-1000*1024*1024
uscm=uscb/1024/1024
uscg=uscm/1024
uscg=round(uscg,3)
alcb=20*1024*1024*1024
alcm=alcb/1024/1024
alcg=alcm/1024
alcg=round(alcg,3)
frcb=1000*1024*1024
frcm=frcb/1024/1024
frcg=frcm/1024
frcg=round(frcg,3)
'D盘
usdb=40*1024*1024*1024-30*1024*1024*1024
usdm=usdb/1024/1024
usdg=usdm/1024
usdg=round(usdg,3)
aldb=40*1024*1024*1024
aldm=aldb/1024/1024
aldg=aldm/1024
aldg=round(aldg,3)
frdb=30*1024*1024*1024
frdm=frdb/1024/1024
frdg=frdm/1024
frdg=round(frdg,3)
'E盘
useb=80*1024*1024*1024-60*1024*1024*1024
usem=useb/1024/1024
useg=usem/1024
useg=round(useg,3)
aleb=80*1024*1024*1024
alem=aleb/1024/1024
aleg=alem/1024
aleg=round(aleg,3)
freb=60*1024*1024*1024
frem=freb/1024/1024
freg=frem/1024
freg=round(freg,3)
'F盘
usfb=20*1024*1024*1024
usfm=usfg/1024/1024
usfg=usfm/1024
usfg=round(usfg,3)
alfb=300*1024*1024*1024-alcb-aldb-aleb
alfm=alfb/1024/1024
alfg=alfm/1024
alfg=round(alfg,3)
frfb=alfb-usfb
frfm=frfg/1024/1024
frfg=frfm/1024
frfg=round(frfg,3)
msgbox "C盘总大小: "&alcg&"G"&" "&alcm&"M"&" "&alcb&"B"&chr(10)&"C盘已用空间:"&uscg&"G"&" "&uscm&"M"&" "&uscb&"B"&chr(10)&"C盘可用空间:"&frcg&"G"&" "&frcm&"M"&" "&frcb&"B"&chr(10)&chr(10)&"D盘总大小 :"&aldg&"G"&" "&aldm&"M"&" "&aldb&"B"&chr(10)&"D盘已用空间:"&usdg&"G"&" "&usdm&"M"&" "&usdb&"B"&chr(10)&"D盘可用空间:"&frdg&"G"&" "&frdm&"M"&" "&frdb&"B"&chr(10)&chr(10)&"E盘总大小 :"&aleg&"G"&" "&alem&"M"&" "&aleb&"B"&chr(10)&"E盘已用空间:"&useg&"G"&" "&usem&"M"&" "&useb&"B"&chr(10)&"E盘可用空间:"&freg&"G"&" "&frem&"M"&" "&freb&"B"&chr(10)&chr(10)&"F盘总大小 :"&alfg&"G"&" "&alfm&"M"&" "&alfb&"B"&chr(10)&"F盘已用空间:"&usfg&"G"&" "&usfm&"M"&" "&usfb&"B"&chr(10)&"F盘可用空间:"&frfg&"G"&" "&frfm&"M"&" "&frfb&"B",vbinformation,"$$$夜七制作$$$"

I'll interject, omitting the reading of the text. Hehe
Just some things I don't quite understand the meaning of the LZ's title...
'C drive
uscb=20*1024*1024*1024-1000*1024*1024
uscm=uscb/1024/1024
uscg=uscm/1024
uscg=Round(uscg,3)
alcb=20*1024*1024*1024
alcm=alcb/1024/1024
alcg=alcm/1024
alcg=Round(alcg,3)
frcb=1000*1024*1024
frcm=frcb/1024/1024
frcg=frcm/1024
frcg=Round(frcg,3)
'D drive
usdb=40*1024*1024*1024-30*1024*1024*1024
usdm=usdb/1024/1024
usdg=usdm/1024
usdg=Round(usdg,3)
aldb=40*1024*1024*1024
aldm=aldb/1024/1024
aldg=aldm/1024
aldg=Round(aldg,3)
frdb=30*1024*1024*1024
frdm=frdb/1024/1024
frdg=frdm/1024
frdg=Round(frdg,3)
'E drive
useb=80*1024*1024*1024-60*1024*1024*1024
usem=useb/1024/1024
useg=usem/1024
useg=Round(useg,3)
aleb=80*1024*1024*1024
alem=aleb/1024/1024
aleg=alem/1024
aleg=Round(aleg,3)
freb=60*1024*1024*1024
frem=freb/1024/1024
freg=frem/1024
freg=Round(freg,3)
'F drive
usfb=20*1024*1024*1024
usfm=usfg/1024/1024
usfg=usfm/1024
usfg=Round(usfg,3)
alfb=300*1024*1024*1024-alcb-aldb-aleb
alfm=alfb/1024/1024
alfg=alfm/1024
alfg=Round(alfg,3)
frfb=alfb-usfb
frfm=frfg/1024/1024
frfg=frfm/1024
frfg=Round(frfg,3)
MsgBox "Total C drive size: " & alcg & "G" & " " & alcm & "M" & " " & alcb & "B" & Chr(10) & "Used space on C drive:" & uscg & "G" & " " & uscm & "M" & " " & uscb & "B" & Chr(10) & "Available space on C drive:" & frcg & "G" & " " & frcm & "M" & " " & frcb & "B" & Chr(10) & Chr(10) & "Total D drive :" & aldg & "G" & " " & aldm & "M" & " " & aldb & "B" & Chr(10) & "Used space on D drive:" & usdg & "G" & " " & usdm & "M" & " " & usdb & "B" & Chr(10) & "Available space on D drive:" & frdg & "G" & " " & frdm & "M" & " " & frdb & "B" & Chr(10) & Chr(10) & "Total E drive :" & aleg & "G" & " " & alem & "M" & " " &aleb& "B" & Chr(10) & "Used space on E drive:" & useg & "G" & " " & usem & "M" & " " & useb & "B" & Chr(10) & "Available space on E drive:" & freg & "G" & " " & frem & "M" & " " & freb & "B" & Chr(10) & Chr(10) & "Total F drive :" & alfg & "G" & " " & alfm & "M" & " " & alfb & "B" & Chr(10) & "Used space on F drive:" & usfg & "G" & " " & usfm & "M" & " " & usfb & "B" & Chr(10) & "Available space on F drive:" & frfg & "G" & " " & frfm & "M" & " " & frfb & "B", vbInformation, "$$$Made by Ye Qi$$$"

|
|
2007-5-9 13:13 |
|
|
zhoushijay
高级用户
    Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
额……C盘可用空间好像写错了
Uh... The available space on drive C seems to be miswritten
|
|
2007-5-9 13:15 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
那楼主的意思是:
先读取盘数,然后把前面的盘符的容量等读出来,留着最后一个要算(就是不准读)是这个意思吗?
Then the LZ's meaning is: First read the number of disks, then read out the capacity and other information of the previous drive letters, and keep the last one to be calculated (that is, not allowed to read). Is this the meaning?
|
|
2007-5-9 23:50 |
|
|
wld
初级用户
 
积分 61
发帖 32
注册 2007-5-9
状态 离线
|
|
2007-5-10 16:51 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by youxi01 at 2007-5-9 11:50 PM:
那楼主的意思是:
先读取盘数,然后把前面的盘符的容量等读出来,留着最后一个要算(就是不准读)是这个意思吗?
嗯,是呀。。
所有的项目都给出了条件呢。。
用四则运算就可以求出来的。。
Originally posted by youxi01 at 2007-5-9 11:50 PM:
So the meaning of the original poster is:
First read the number of disks, then read the capacity and other information of the previous drive letters, and keep the last one to be calculated (that is, not allowed to read). Is that the meaning?
Hmm, yes. ..
All items have given conditions...
It can be calculated by four arithmetic operations. ..
|

知,不觉多。不知,乃求知 |
|
2007-5-10 17:19 |
|
|
hhasee
初级用户
 
积分 185
发帖 88
注册 2008-5-12
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
能发一个在VISTA下也可以用的吗?
Can you send one that can also be used under VISTA?
|
|
2009-1-10 18:11 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
@echo off&setlocal enabledelayedexpansion
::for 内的临时变量用_v1,_v2,_v(n)
::disk=硬盘总容量/1024
::_n=分区数
::for1 读邓正确的字符串,if 是盘f:,去除??-()等符号
:: _d:盘符 _zc:总容量串 _yc:已用空间串
::for2 字符串分段
:: _zt:总容量串头部分 _zw:尾 _yt:已用空间串头部分 _yw:尾
::for3 计算F:总空间及剩余空间
:: 使用临时变量 _v1,_v2,_v3
::for4 处理以M/G为单位的结果
:: _zm:总容量 _ym:已用空间 _sm:乘余空间
::for5 处理成字节(B),兆M/G
:: _zb:总字节B _yb:已用字节B _sb:剩余字节
::for6 显示输出
echo off
set /a disk=300*1024*1024
::for1 读正确的数字串,去除??()等符号
set _n=0
echo.读入数据&echo.************************************
for /f "tokens=1,2,3* delims= " %%i in ('findstr : drivers.txt') do (
set /a _n+=1&echo %%i %%j %%k
set _v1=%%i&set _v2=%%j&set _v3=%%k
if "!_v1!"=="F:" set _v2=!_v2:?=!&set _v3=!_v3:*-=!&set _v3=!_v3:^)=!&set _y!_n!=!_v3!
set _d!_n!=!_v1!&set _z!_n!=!_v2!&set _s!_n!=!_v3!
)
echo.************************************&echo.&echo.
::for2 数字串分段处理
:: _zt:总容量串头部分 _zw:尾 _yt:已用空间串头部分 _yw:尾
for /l %%a in (1,1,!_n!) do (
set _v2=!_z%%a!&set _v3=!_s%%a!&set _v4=!_y%%a!
set _zt%%a=!_v2:~0,-5!
set _zw%%a=!_v2:~-4!
set _st%%a=!_v3:~0,-5!
set _sw%%a=!_v3:~-4!
set _yt%%a=!_v4:~0,-5!
set _yw%%a=!_v4:~-4!
)
::for3 计算F:总空间及剩余空间
:: 使用临时变量 _v1,_v2,_v3
set _v1=
for /l %%a in (1,1,!_n!) do (
set /a _zt%%a=!_zt%%a!&set /a _st%%a=!_st%%a!&set /a _yt%%a=!_yt%%a!
if "!_d%%a!"=="F:" (set /a _zt%%a=!disk!-!_v1!&set /a _st%%a=!_zt%%a!-!_yt%%a!&set _zw%%a=!_yw%%a!) else (set /a _yt%%a=!_zt%%a!-!_st%%a!&set _yw%%a=!_zw%%a!&set /a _v1=!_v1!+!_zt%%a!)
)
::for4 计算以M单位,大于1000M以G为单位的结果
:: _zm:总容量 _sm:乘余空间 _ym:已用空间
for /l %%a in (1,1,!_n!) do (
set /a _zm%%a=!_zt%%a!/1024&set /a _sm%%a=!_st%%a!/1024&set /a _ym%%a=!_yt%%a!/1024
if !_zm%%a! leq 1000 (set _zm%%a=^(!_zm%%a!M^)) else (set /a _zm%%a=!_zm%%a!/1024 & set _zm%%a=^(!_zm%%a!G^))
if !_sm%%a! leq 1000 (set _sm%%a=^(!_sm%%a!M^)) else (set /a _sm%%a=!_sm%%a!/1024 & set _sm%%a=^(!_sm%%a!G^))
if !_ym%%a! leq 1000 (set _ym%%a=^(!_ym%%a!M^)) else (set /a _ym%%a=!_ym%%a!/1024 & set _ym%%a=^(!_ym%%a!G^))
)
::for5 处理成字节显示(B)
:: _zb:总B _yb:已用B _sb:剩余字节
for /l %%a in (1,1,!_n!) do (
rem 把%1 乘以 %2 放入%3所指的变量中
call :sub !_zt%%a! !_zw%%a! _zb%%a
call :sub !_st%%a! !_sw%%a! _sb%%a
call :sub !_yt%%a! !_yw%%a! _yb%%a
)
::for6 显示输出
echo.硬盘数据:
echo._______________________________________________________________________________
for /l %%a in (1,1,!_n!) do (echo.!_d%%a! 总容量:!_zb%%a!!_zm%%a! 剩余:!_sb%%a!!_sm%%a! 已用:!_yb%%a!!_ym%%a!)
echo._______________________________________________________________________________
pause
goto :eof
:sub
set _v1=%1&set _v2=%2&set _v3=%3
set /a _vt=!_v1:~0,-5!*!_v2!
set /a _vw=!_v1:~-5!*!_v2!
set _vx=!_vt!00000
set /a _vy=!_vx:~-9!+!_vw!
set _vx=!_vx:~0,-9!
set _v4=!_vy:~0,-9!
if not "!_va!"=="" set /a _vx=!_vx!+!_v4!
set !_v3!=!_vx!!_vy!
goto :eof
Last edited by netbenton on 2009-1-11 at 23:07 ]
@echo off&setlocal enabledelayedexpansion
::Temporary variables in for are _v1, _v2, _v(n)
::disk=Total hard disk capacity/1024
::_n=Number of partitions
::for1 Read correct string, if it is drive f:, remove symbols like??-() etc.
:: _d:Drive letter _zc:Total capacity string _yc:Used space string
::for2 Segment the string
:: _zt:Head part of total capacity string _zw:Tail _yt:Head part of used space string _yw:Tail
::for3 Calculate total space and free space of F:
:: Use temporary variables _v1, _v2, _v3
::for4 Process results in units of M/G
:: _zm:Total capacity _sm:Free space _ym:Used space
::for5 Process into bytes (B), megabytes M/G
:: _zb:Total bytes B _yb:Used bytes B _sb:Free bytes
::for6 Display output
echo off
set /a disk=300*1024*1024
::for1 Read correct numeric string, remove??() etc.
set _n=0
echo. Reading data&echo.************************************
for /f "tokens=1,2,3* delims= " %%i in ('findstr : drivers.txt') do (
set /a _n+=1&echo %%i %%j %%k
set _v1=%%i&set _v2=%%j&set _v3=%%k
if "!_v1!"=="F:" set _v2=!_v2:?=!&set _v3=!_v3:*-=!&set _v3=!_v3:^)=!&set _y!_n!=!_v3!
set _d!_n!=!_v1!&set _z!_n!=!_v2!&set _s!_n!=!_v3!
)
echo.************************************&echo.&echo.
::for2 Segment processing of numeric string
:: _zt:Head part of total capacity string _zw:Tail _yt:Head part of used space string _yw:Tail
for /l %%a in (1,1,!_n!) do (
set _v2=!_z%%a!&set _v3=!_s%%a!&set _v4=!_y%%a!
set _zt%%a=!_v2:~0,-5!
set _zw%%a=!_v2:~-4!
set _st%%a=!_v3:~0,-5!
set _sw%%a=!_v3:~-4!
set _yt%%a=!_v4:~0,-5!
set _yw%%a=!_v4:~-4!
)
::for3 Calculate total space and free space of F:
:: Use temporary variables _v1, _v2, _v3
set _v1=
for /l %%a in (1,1,!_n!) do (
set /a _zt%%a=!_zt%%a!&set /a _st%%a=!_st%%a!&set /a _yt%%a=!_yt%%a!
if "!_d%%a!"=="F:" (set /a _zt%%a=!disk!-!_v1!&set /a _st%%a=!_zt%%a!-!_yt%%a!&set _zw%%a=!_yw%%a!) else (set /a _yt%%a=!_zt%%a!-!_st%%a!&set _yw%%a=!_zw%%a!&set /a _v1=!_v1!+!_zt%%a!)
)
::for4 Calculate results in units of M, if greater than 1000M, use G as unit
:: _zm:Total capacity _sm:Free space _ym:Used space
for /l %%a in (1,1,!_n!) do (
set /a _zm%%a=!_zt%%a!/1024&set /a _sm%%a=!_st%%a!/1024&set /a _ym%%a=!_yt%%a!/1024
if !_zm%%a! leq 1000 (set _zm%%a=^(!_zm%%a!M^)) else (set /a _zm%%a=!_zm%%a!/1024 & set _zm%%a=^(!_zm%%a!G^))
if !_sm%%a! leq 1000 (set _sm%%a=^(!_sm%%a!M^)) else (set /a _sm%%a=!_sm%%a!/1024 & set _sm%%a=^(!_sm%%a!G^))
if !_ym%%a! leq 1000 (set _ym%%a=^(!_ym%%a!M^)) else (set /a _ym%%a=!_ym%%a!/1024 & set _ym%%a=^(!_ym%%a!G^))
)
::for5 Process into byte display (B)
:: _zb:Total B _yb:Used B _sb:Free bytes
for /l %%a in (1,1,!_n!) do (
rem Multiply %1 by %2 and put it in the variable pointed to by %3
call :sub !_zt%%a! !_zw%%a! _zb%%a
call :sub !_st%%a! !_sw%%a! _sb%%a
call :sub !_yt%%a! !_yw%%a! _yb%%a
)
::for6 Display output
echo.Hard disk data:
echo._______________________________________________________________________________
for /l %%a in (1,1,!_n!) do (echo.!_d%%a! Total capacity:!_zb%%a!!_zm%%a! Free:!_sb%%a!!_sm%%a! Used:!_yb%%a!!_ym%%a!)
echo._______________________________________________________________________________
pause
goto :eof
:sub
set _v1=%1&set _v2=%2&set _v3=%3
set /a _vt=!_v1:~0,-5!*!_v2!
set /a _vw=!_v1:~-5!*!_v2!
set _vx=!_vt!00000
set /a _vy=!_vx:~-9!+!_vw!
set _vx=!_vx:~0,-9!
set _v4=!_vy:~0,-9!
if not "!_va!"=="" set /a _vx=!_vx!+!_v4!
set !_v3!=!_vx!!_vy!
goto :eof
Last edited by netbenton on 2009-1-11 at 23:07 ]
|

精简
=> 个人 网志  |
|
2009-1-11 23:04 |
|
|
knoppix7
银牌会员
    
积分 1287
发帖 634
注册 2007-5-2 来自 cmd.exe
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
DISKPART> list disk
外部命令的定义还没有...就这样了...
DISKPART> list disk
The definition of the external command has not been... That's it...
|
|
2009-1-12 09:40 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
不解:
或许还不了解楼主的意思!
还要定义什么外部命令呀?
Puzzled:
Maybe you still don't understand the LZ's meaning!
What external commands need to be defined?
|

精简
=> 个人 网志  |
|
2009-1-12 14:46 |
|
|