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%. How do I fix this? Thanks In Advance
答案 0 :(得分:0)
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")
答案 1 :(得分:0)
A few bugs in your script:
You need to initialize OEnd
, not End
set /a OEnd = 0
You need a descriptor for OZ
for bytes, something like
if %OEnd% == 0 (set OZ=Bytes)
And, each of the other checks needs to check the value of OEnd
, not name itself:
if %OEnd% == 1 (set OZ=KB)
if %OEnd% == 2 (set OZ=MB)
if %OEnd% == 3 (set OZ=GB)
if %OEnd% == 4 (set OZ=TB)