Friday, August 1, 2014

command line - Adding variables in a batch file in Windows

I'm trying to fix something that's simple but yet can't seem to put my finger on it.


I have this very simple batch file that when you drop a folder on it it converts a bunch of files to another format. I'm trying to add a progress indicator to the title bar but for some reason I can't get the set /a to add a value and return anything other than the value I initially put in.
here's the code


set Count=0
set NumFiles=0
set oldpct=-1
for %%A in (*.t64) do set /A NumFiles += 1
echo File count = %NumFiles%
echo.
echo Converting...
rem Parse every file in the folder and perform the magic.
for %%x in (*.t64) do (
set /A "Count += 1"
echo count: %Count%
pause
set /A pct=100*%Count%/%NumFiles%
%C1541_PATH%\c1541.exe -verbose off -silent on -format "fromt64,01" d64 "%%~nx.d64" -tape "%%x"
rem calculate progress
if "%pct%" gtr "%oldPct%" (
set oldPct=%pct%
echo %pct%
title Progress: %pct%/100
)
)
pause
exit
:F_Error
cls
echo FILE ERROR
echo.
echo This script only works on folders, not individual files.
pause
exit
:Error
cls
echo ---------------------- ERROR! ----------------------
echo.
echo Please drag and drop a folder on this batch file!
echo Please make sure C1541.exe is in the
echo correct folder and that the path value in
echo this file points to it.
echo Look near the top of the script, it is identified.
echo.
pause
exit

I deliberately omitted a part of the code at the start and the end in order to keep things short.


For some reason, the %count% and the %pct% refuses to be calculated...


When I try using delayedexpansion, I get this message


invalid filename error


But since it's a script that doesn't rely on the WOW64 or wmic, it shouldn't really matter the bit size I'm using (the command prompt smooths out everything)

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...