Dealing with %1
, shift or %*
could fail with drag&drop, because the explorer is not very smart, when it creates the command line.
Files like Cool&stuff.cue
are not quoted by the explorer so you get a cmdline like
pcutmp3.bat Cool&stuff.cue
So in %1
is only Cool
even in %*
is only Cool
, but after the pcutmp3.bat ends, cmd.exe tries to execute a stuff.cue
.
To handle with this stuff you could use this, it catch all filenames by using the cmdcmdline
variable.
@echo off
setlocal DisableDelayedExpansion
set index=0
setlocal EnableDelayedExpansion
rem *** Take the cmd-line, remove all until the first parameter
rem *** Copy cmdcmdline without any modifications, as cmdcmdline has some strange behaviour
set "params=!cmdcmdline!"
set "params=!params:~0,-1!"
set "params=!params:*" =!"
echo params: !params!
rem Split the parameters on spaces but respect the quotes
for %%G IN (!params!) do (
for %%# in (!index!) do (
endlocal
set /a index+=1
set "item_%%#=%%~G"
setlocal EnableDelayedExpansion
)
)
set /a max=index-1
rem list the parameters
for /L %%n in (0,1,!max!) DO (
echo %%n #!item_%%n!#
)
pause
REM ** The exit is important, so the cmd.exe doesn't try to execute commands after ampersands
exit
Btw. there is a line limit for drag&drop operations of ~2048 characters, in spite of the "standard" batch line limit of 8191 characters.