Page 1 of 1

How do I convert batch script arguments to pattern?

Posted: 31 Mar 2021 07:48
by PiotrMP006
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

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

Posted: 31 Mar 2021 08:26
by Compo
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!%

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

Posted: 31 Mar 2021 08:37
by PiotrMP006
For space don't work

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

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

Posted: 31 Mar 2021 09:41
by Compo
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!"%

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

Posted: 05 Apr 2021 02:27
by PiotrMP006
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

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

Posted: 05 Apr 2021 10:53
by Squashman
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.

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

Posted: 06 Apr 2021 14:08
by miskox
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