Page 1 of 1
How to convert argument list to skip first argument?
Posted: 13 Jun 2023 08:23
by PiotrMP006
How to convert argument list to skip first argument?
%* = "C:\7-Zip Test\" "File&Test 1.txt" "File&Test 2.txt" "File&Test 3.txt"
After conversion, this should be the argument list
%filelist% = "File&Test 1.txt" "File&Test 2.txt" "File&Test 3.txt"
Please help
Re: How to convert argument list to skip first argument?
Posted: 13 Jun 2023 08:39
by miskox
Re: How to convert argument list to skip first argument?
Posted: 13 Jun 2023 08:50
by PiotrMP006
I need a solution with a FOR loop without SHIFT
Re: How to convert argument list to skip first argument?
Posted: 13 Jun 2023 11:06
by miskox
How do you get this list?
Code: Select all
@echo off
echo %*
set par_list=&rem
:0
shift
set par_list=%par_list% %1
if not "%2"=="" goto :0
echo %par_list%
Output:
Code: Select all
c:\>some_bat.cmd "a" "b" "c" "d"
"a" "b" "c" "d"
"b" "c" "d"
c:\>
viewtopic.php?p=38525#p38525
Saso
Re: How to convert argument list to skip first argument?
Posted: 13 Jun 2023 11:43
by mataha
Code: Select all
@echo off & setlocal EnableDelayedExpansion
set skip=
set args=
for %%p in (%*) do (
if not defined skip (
set "skip=true"
) else if not defined args (
set "args=%%p"
) else (
set "args=!args! %%p"
)
)
Re: How to convert argument list to skip first argument?
Posted: 14 Jun 2023 08:37
by IcarusLives
You could do it this way
Code: Select all
@echo off & setlocal enableDelayedExpansion
call :function "one" "two" "three" "four" "five"
pause & exit
:function
set /a "SKIP=1", "args=0"
set /a "start=1 + skip"
for %%i in (%*) do (
set /a "args+=1"
set "func[!args!]=%%~i"
)
for /l %%i in (%start%,1,%args%) do (
echo !func[%%i]!
)
goto :eof