Here's some code from this great answer which doesn't solve my scenario.
See line 22
where I tried to address this.
@echo off
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:*" =!"
set count=0
rem Split the parameters on spaces but respect the quotes
for %%G IN (!params!) do (
set /a count+=1
set "item_!count!=%%~G"
rem echo !count! %%~G
)
rem list the parameters
for /L %%n in (1,1,!count!) DO (
rem Original line, works fine
rem echo %%n #!item_%%n!#
rem This works fine with !item_%%~n!
echo !item_%%~n!
rem This doesn't when I try to expand n to the path.
echo !item_%%~pn!
)
pause
REM ** The exit is important, so the cmd.exe doesn't try to execute commands after ampersands
exit
I would ideally like to expand on the !item_%%n!
variable to !item_%%~pn!
to get the path for example but I cannot figure out how to modify that code to do this.
I thought the item
variable held the path and the n
variable then counted through them.
I would like to be able to expand to these others, like normal:
%%~A &rem expands %%A removing any surrounding quotes (")
%%~dA &rem expands %%A to a drive letter only
%%~fA &rem expands %%A to a fully qualified path name
%%~pA &rem expands %%A to a path only
%%~nA &rem expands %%A to a file name only
%%~xA &rem expands %%A to a file extension only
%%~sA &rem expanded path contains short names only
%%~aA &rem expands %%A to file attributes of file
%%~tA &rem expands %%A to date/time of file
%%~zA &rem expands %%A to size of file
%%~dpA &rem expands %%A to a drive letter and path only
%%~nxA &rem expands %%A to a file name and extension only
%%~fsA &rem expands %%A to a full path name with short names only
%%~dp$dir:A &rem searches the directories listed in the 'dir' environment variable and expands %%A to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string
%%~ftzaA &rem expands %%A to a DIR like output line