I've probably pushed myself into a corner here but for some reason this batch will handle pretty much any name except one with a !
in it. I cannot figure out why for the life of me what I've done wrong.
If the file has a !
in the name it ignores it and creates a new one with no !
which gets moved into the batch directory.
Actually every instance of that file name ends up missing the !
even the quote in the output MGL:
setlocal enabledelayedexpansion
set choice=
set /p choice= Type selection and press enter:
if '%choice%'=='1' set console=SNES
if '%choice%'=='1' set settings=delay="2" type="f" index="0"
if '%choice%'=='2' set console=PSX
if '%choice%'=='2' set settings=delay="1" type="s" index="0"
if '%choice%'=='3' set console=gameboy
if '%choice%'=='3' set settings=delay="1" type="f" index="1"
if '%choice%'=='4' set console=C64
if '%choice%'=='4' set settings=delay="1" type="f" index="1"
mkdir MGL_!console! > nul 2>&1
for /R %%a in (*.32x,*.a26,*.a78,*.abs,*.bin,*.bs,*.chd,*.cof,*.col,*.fds,*.gb,*.gbc,*.gba,*.gg,*.j64,*.jag,*.lnx,*.md,*.neo,*.nes,*.o,*.pce,*.rom,*.sc,*.sfc,*.sg,*.smc,*.smd,*.sms,"*.vec",*.wsc,*.ws) do (
set "filepath=%%a"
set "filepath=!filepath:%CD%=!"
set "filepath=!filepath:\=/!"
set "filepath=!filepath:~1!"
echo ^<mistergamedescription^> > "%%~pna.mgl"
echo ^<rbf^>_console/!console!^</rbf^> >> "%%~pna.mgl"
echo ^<file !settings! path="!filepath!"/^> >> "%%~pna.mgl"
echo ^</mistergamedescription^> >> "%%~pna.mgl"
>nul move "%%~pna.mgl" "MGL_%console%\%%~na.mgl"
)
The output seems fine the whole way though?
echo </mistergamedescription> 1>>"\mISTER\Done\Vectrex\1 World - A-Z\Blitz! - Action Football (USA, Europe) (0F11CE0C).mgl"
move "\mISTER\Done\Vectrex\1 World - A-Z\Blitz! - Action Football (USA, Europe) (0F11CE0C).mgl" "MGL_!console!\Blitz! - Action Football (USA, Europe) (0F11CE0C).mgl" 1>nul
)
The system cannot find the file specified.
I believe the issue is caused by the fact that delayed expansion is enabled during expansion of
%%a
, because there is an exclamation mark in the affected path (\Blitz! - *
), which becomes lost due to delayed expansion. Therefore, you need to toggle delayed expansion, so it is only enabled where actually needed. Here is an improved approach, also featuring several other improvements:Anyway, I still do not get if you really want to overwrite the
*.mgl
file in everyfor /R
loop iteration.