Needed to convert several SVGs to PNG, and discovered the free Inkscape easily can be used in batch scripts.
The following .bat file will convert all SVGs dropped on it to a PNG with height 48 placed next to the original SVG. More options can be found in the Inkscape manual.
for %%f in (%*) do (
"C:\Program Files\Inkscape\inkscape.exe" ^
Sometimes you want a batch file to always run with the directory of the script as the working directory. Not whatever directory you ran it from.
pushd changes the directory to
%~dp0, which is the directory of the running batch script.
popd returns to whatever it was when the script started running. Not sure if the last step is necessary, but there you go anyways 🙂
Tried to make a helpful batch script for something at work and learned some new things I thought I’d write down here so I know where to find it later.
Turn off echoing
Should be known by everyone really, but in case you don’t. Prevents the commands in the batch script and the command prompt to show up while the script is running. Beginning a line with @ does this for a single command.
REM Some comment
REM Will still appear as a command if you haven't disabled echoing
Labels and goto
Trivial, but I keep forgetting about this since I never use it in other programming.
REM Will be skipped
Set title of command prompt
title MyScript: Doing x now
Check command line arguments
if "%~1"=="" (echo Usage: test.bat path && goto end)
if not exist %~1 (echo %~1 does not exist && goto end)
choice /c ny /n /d y /t 10 /m "Do you really want to do this? [y=10s,n]
if ERRORLEVEL 2 (
echo Ok, I'll do it
Run other batch scripts
If you don’t use the call command, the other script will actually take over and your script will end.
call other.bat arg1 arg2 ...
Do the same thing with various subjects
for %%x in (
) do (