[英]Batch Script Won't Display Variable
I have a Batch Script which when I run wont display a string variable. 我有一个批处理脚本,运行时不会显示字符串变量。
@ECHO OFF
color 0c
set /a Copyed = 1
set /a File = %random%
set /a Origin = %~z1
set /a End = 0
set /a OSize = %~z1
if %~z1 LEQ 999 (
set /a Size = %~z1
set Z="Bytes"
)
if %OSize% GEQ 1000 (
set /a OSize /= 1000
set /a OEnd += 1
)
if %OSize% GEQ 1000 (
set /a OSize /= 1000
set /a OEnd += 1
)
if %OSize% GEQ 1000 (
set /a OSize /= 1000
set /a OEnd += 1
)
if %OSize% GEQ 1000 (
set /a OSize /= 1000
set /a OEnd += 1
)
if OEnd == 1 (set OZ="KB")
if OEnd == 2 (set OZ="MB")
if OEnd == 3 (set OZ="GB")
if OEnd == 4 (set OZ="TB")
echo ::::::::::::::::::::::: > %File%
echo :::::::::::::::::::::::
echo Original File "%1" Has A Size Of %OSize% %OZ% >> %File%
echo Original File "%1" Has A Size Of %OSize% %OZ%
pause
When I run this script using another file I get : 当我使用另一个文件运行此脚本时,我得到:
:::::::::::::::::::::::
Original File ""P:\Virus Testing\Fill.txt"" Has A Size Of 536
Press any key to continue . . .
In the file it creates I get this : 在文件中创建我得到这个:
:::::::::::::::::::::::
Original File ""P:\Virus Testing\Fill.txt"" Has A Size Of 536
As you can see neither of them display the varible %OZ%. 如您所见,它们都不显示变量%OZ%。 How do I fix this?
我该如何解决? Thanks In Advance
提前致谢
Try 尝试
if %OEnd% == 1 (set OZ="KB")
if %OEnd% == 2 (set OZ="MB")
if %OEnd% == 3 (set OZ="GB")
if %OEnd% == 4 (set OZ="TB")
A few bugs in your script: 脚本中的一些错误:
You need to initialize OEnd
, not End
您需要初始化
OEnd
,而不是End
set /a OEnd = 0
You need a descriptor for OZ
for bytes, something like 您需要一个用于
OZ
的描述符(用于字节),例如
if %OEnd% == 0 (set OZ=Bytes)
And, each of the other checks needs to check the value of OEnd
, not name itself: 并且,其他每个检查都需要检查
OEnd
的值,而不是自己命名:
if %OEnd% == 1 (set OZ=KB)
if %OEnd% == 2 (set OZ=MB)
if %OEnd% == 3 (set OZ=GB)
if %OEnd% == 4 (set OZ=TB)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.