How do I convert batch script arguments to pattern?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

How do I convert batch script arguments to pattern?

#1 Post by PiotrMP006 » 31 Mar 2021 07:48

Hi

How do I convert batch script arguments to pattern?

-ai!test1.7z -ai!test2.7z -ai!test3.7z

%1 = test1.7z
%2 = test2.7z
%3 = test3.7z

%* = test1.7z test2.7z test3.7z

Please help

Compo
Posts: 538
Joined: 21 Mar 2014 08:50

Re: How do I convert batch script arguments to pattern?

#2 Post by Compo » 31 Mar 2021 08:26

If your input files are all unquoted, and do not contain spaces or other potentially poison characters, then you could probably simply use something like this:

Code: Select all

@Set "allinput=%*"
@Echo -ai!%allinput: = -ai!%

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

Re: How do I convert batch script arguments to pattern?

#3 Post by PiotrMP006 » 31 Mar 2021 08:37

For space don't work

%* =" test 1.7z" "test 2.7z" "test 3.7z"

Compo
Posts: 538
Joined: 21 Mar 2014 08:50

Re: How do I convert batch script arguments to pattern?

#4 Post by Compo » 31 Mar 2021 09:41

Please don't try to disrespect me, I was very clear in my opening statement of my last response.

You've completely changed your input to include both spaces and doublequotes, and would obviously not therefore, be splitting the string on spaces, would you?

You'd be splitting on a doublequote space doublequote sequence:

Code: Select all

@Set "allinput=%*"
@Echo -ai!%allinput:" "=" -ai!"%

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

Re: How do I convert batch script arguments to pattern?

#5 Post by PiotrMP006 » 05 Apr 2021 02:27

Hi

It doesn't work if names don't always have quotation marks.

Names without spaces do not have quotation marks (Total Commander %S).



ex

%* Test1.7z "Test 2.zip" Test2.rar

%1 Test1.7z
%2 "Test 2.zip"
%3 Test3.rar

Please help me

Squashman
Expert
Posts: 4292
Joined: 23 Dec 2011 13:59

Re: How do I convert batch script arguments to pattern?

#6 Post by Squashman » 05 Apr 2021 10:53

PiotrMP006 wrote:
05 Apr 2021 02:27
Names without spaces do not have quotation marks (Total Commander %S).
What about names with an ampersand and other special characters?

I am also concerned about your usage of the exclamation point. As that has special meaning in batch files as well when delayed expansion is enabled.

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

Re: How do I convert batch script arguments to pattern?

#7 Post by miskox » 06 Apr 2021 14:08

In total commander try using %P%S. Maybe this will help.

Or use %s (lowercase s).

Maybe better solution might be to use SHIFT in a loop to move parameters into variables.

Saso

Post Reply