How to convert argument list to skip first argument?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PiotrMP006
Posts: 31
Joined: 08 Sep 2017 06:10

How to convert argument list to skip first argument?

#1 Post by PiotrMP006 » 13 Jun 2023 08:23

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

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: How to convert argument list to skip first argument?

#2 Post by miskox » 13 Jun 2023 08:39

Use

Code: Select all

shift
See

Code: Select all

help shift
Saso

PiotrMP006
Posts: 31
Joined: 08 Sep 2017 06:10

Re: How to convert argument list to skip first argument?

#3 Post by PiotrMP006 » 13 Jun 2023 08:50

I need a solution with a FOR loop without SHIFT

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: How to convert argument list to skip first argument?

#4 Post by miskox » 13 Jun 2023 11:06

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

mataha
Posts: 35
Joined: 27 Apr 2023 12:34

Re: How to convert argument list to skip first argument?

#5 Post by mataha » 13 Jun 2023 11:43

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"
    )
)

IcarusLives
Posts: 175
Joined: 17 Jan 2016 23:55

Re: How to convert argument list to skip first argument?

#6 Post by IcarusLives » 14 Jun 2023 08:37

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

Post Reply