solved - no bug [TC 11.00b6] /W parameter for cm_commands does not always work

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
petermad
Power Member
Power Member
Posts: 16032
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

solved - no bug [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *petermad »

If I make an em_command like this:

Code: Select all

[em_CopyCurrentToBak]
cmd=cm_Copy /
param=T="%P*.bak"W="%N"
it works as expected if the file under the caret does NOT contains spaces.

If I change the command to:

Code: Select all

[em_CopyCurrentToBak]
cmd=cm_Copy /
param=T="%P*.bak"W=""%N""
it works if the file under the caret contains spaces, but then it does not work for files without spaces.


If I use:

Code: Select all

[em_CopyCurrentToBak]
cmd=cm_Copy /
param=T="%P*.bak"W="%N"
And there are spaces in the filename, then the field: "Only filenames of this type" is blank


If I use:

Code: Select all

[em_CopyCurrentToBak]
cmd=cm_Copy /
param=T="%P*.bak"W="%O.*"
And there are spaces in the filename, then the field: "Only filenames of this type" will be filled out with the value of %O.* but it will not work because of the missing quotes.

This also applies to the cm_Copy and the cm_RenMov commands.
Last edited by petermad on 2023-06-14, 10:46 UTC, edited 1 time in total.
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50532
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *ghisler(Author) »

param=T="%P*.bak"W=""%N""
The syntax is wrong. If you want double quotes within double quotes, you have to list them twice ""
So it would look like this:
param=T="%P*.bak"W="""%N"""
There are 3: The opening double quote, and then the doubled ones. otherwise TC would think that the parameter would end after the second one.
Author of Total Commander
https://www.ghisler.com
User avatar
petermad
Power Member
Power Member
Posts: 16032
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *petermad »

2ghisler(Author)

Code: Select all

param=T="%P*.bak"W="""%N"""
does not work either.

Try with these 4 filenames:
aabb.fil
aabb.txt
aa bb.fil
aa bb.txt

The first and second one works fine, and puts "aabb.fil" or "aabb.txt" in the "Only files of this type" field.
The third one (aa bb.fil) puts " in the "Only files of this type" field.
The fourth one (aa bb.txt) give the error message: Wrong parameters specified! txt"""

Very peculiar with the aa bb.txt file :shock:

EDIT: it is actually any file that has a space in the name part and a T anywhere in in the extension that gives the error message - apparantly TC thinks it is the start of a T= parameter.
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50532
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *ghisler(Author) »

The problem is that %N automatically gets surrounded by double quotes when it contains spaces. You need to turn that off with %Q in this case because you add your own quotes, and they must be doubled. So the result is:
cm_copy /%QT="%P*.bak"W="""%N"""
Author of Total Commander
https://www.ghisler.com
User avatar
petermad
Power Member
Power Member
Posts: 16032
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *petermad »

Thanks

Code: Select all

param=T="%P*.bak"%QW="""%N"""
works :-)

I had tried %Q earlier, but before using triple "s around %N
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
AntonyD
Power Member
Power Member
Posts: 1574
Joined: 2006-11-04, 15:30 UTC
Location: Russian Federation

Re: solved - no bug [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *AntonyD »

2ghisler(Author)
But where in the help can I SEQUENTIALLY read about such necessary actions that should lead to the resulting string?
Maybe the program ITSELF should insert additional quotes, if there is some sequence of a set of command flags ALREADY framed by quotes - so that the user does not rush about in search of an answer - why does it not work? After all, the command described in the first post is the most natural and easily obtained by the user from his thoughts about WHAT he needs to do. AND - the first result which he will get when will try to use it: "it works as expected if the file under the caret does NOT contains spaces"...
#146217 personal license
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50532
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: solved - no bug [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *ghisler(Author) »

No, the problem here is that we have quotes within quotes, something the algorithm couldn't know. That's why you can use %Q and put your own quotes where you want them.
Author of Total Commander
https://www.ghisler.com
User avatar
AntonyD
Power Member
Power Member
Posts: 1574
Joined: 2006-11-04, 15:30 UTC
Location: Russian Federation

Re: solved - no bug [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *AntonyD »

2ghisler(Author)
The meaning of the question is the opposite. As a regular user - in most cases I won't pay attention to the need for quotes at all.
And it is easier and more correct to always determine their necessity by the program itself!
After all, how was that primary command formed, which in fact turned out to be invalid?
let's try to find out... As we know from the help: CM_COPY supports among others these params:

Code: Select all

T="path": Target path, MUST be put in double quotes, and end with a backslash if a directory, 
            or with a file mask with wildcards to rename files
W="wildcards": Copy only files of this type
And I immediately notice that, unless otherwise stated, the order of the parameters must be literal and equal to that stated in the help!
This I mean that if the parameters can be interchanged, then somewhere it is worth mentioning. I haven't seen this yet.
So the initial cmd line will be:

Code: Select all

CM_COPY /T="path_name"W="file_type"
Now we improve our intermediate variables `path_name` && `file_type`
The path should contain the expected final name of the selected file (the file under the cursor) so it will be "*.bak" - we want only to change the extension and help stated that we must use here double quotes...
But stop! we forgot the full path! So it will be "%P*.bak". Here we will use %P = the source path.
Ok this is done, so let move to another var: `file_type`. By this we mean simply current file, the file under the cursor. So obviously it should be simple %N, and as help DOES NOT stated any special for this `W` param - we leave it as-is. This we only replace our variables with their full values.
And SO, finally our line will look like this:

Code: Select all

CM_COPY /T=""%P*.bak""W="%N"
NB! Please pay attention of initially double double quotes for T param. This is done so exactly because the help section ALREADY contains them (see corresponding quote above)!
So I must change only INTERNAL part of the param's value - and the overall view of it is already predefined by you in this help: T="path" and W="wildcards". Double quotes ALREADY MUST exist here!

And that's how everything is. The average user will actually decide that he has fulfilled all the conditions for the formation of this line.
After all, nothing more important/necessary in the help is not said. EVEN in the form of some kind of cross-reference to another help topic.
As a result, exactly this mentioned above line that will be launched .. And .. and nothing will work as it was required.
And now tell me - with the help of which help/which part/section of it, the user should guess what needs to be done to change the view into this:

Code: Select all

T="%P*.bak"%QW="""%N"""
Why can't the program itself do this quietly from the user?
#146217 personal license
User avatar
petermad
Power Member
Power Member
Posts: 16032
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: solved - no bug [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *petermad »

I must admit that it is puzzeling...

If I make this button:

Code: Select all

TOTALCMD#BAR#DATA
cd
?%Q"%N"
wcmicons.dll
Test quotes
Both files with and without spaces are show surrounded with one set of "s

So when the help says that W="wildcards": Copy only files of this type - it is fair to assume that the construction that works in the button here above %Q"%N" just has to be surrounded with quotes - to be expected to work, like /W="%Q"%N"" - but it has to be /W="%Q""%N"""

Maybe a remark in the Help would be in order for the /W parameter:
If you want quotation marks around the wildcard they have to be doubled (wildcard = "a test.*" => /W="""a test.*""")
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50532
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: solved - no bug [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *ghisler(Author) »

When you use the following parameter: /W="%Q"%N""
Then TC sees /W="%Q" because it cannot know that the second quote there isn't the end quote, but somewhere in the middle. That's why you have to repeat the quotes inside quotes:
/W="%Q""%N"""
Here it sees /W=" and knows that the following string until the next " is the parameter. But when it sees "" it knows that the user wanted to have quotes within quotes.
Instead of quotes I could also have used a different character, say square brackets [] as used in the multi-rename tool. However, square brackets are allowed in file names, so we would have the same dilemma again, e.g.
/W=[%Q"%N"]
would solve the problem with repeated double quotes, but would lead to other problems, e.g. when there is a file name like "Simple[Blue]" which would have to be put in these square brackets.
Another alternative would have been to not require quotes for parameters, e.g.
/W=%N
But then there would not be a way to detect where a parameter truly ends, e.g. when using both T= and W= together.
Author of Total Commander
https://www.ghisler.com
User avatar
petermad
Power Member
Power Member
Posts: 16032
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: solved - no bug [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *petermad »

2ghisler(Author)
I see the predicament. But without documentation it can be impossible to guess the syntax - that's why I suggest to add this to the help:
If you want quotation marks around the wildcard they have to be doubled (wildcard = "a test.*" => /W="""a test.*""")
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50532
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: solved - no bug [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *ghisler(Author) »

OK, I will change the description and example to:
Note: If you need double quotes around the wildcards, you need to put them in double quotes twice
Example: CM_COPY /V0H1T="c:\test\"W"""a test.*"" test2.*"
Author of Total Commander
https://www.ghisler.com
User avatar
petermad
Power Member
Power Member
Posts: 16032
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: solved - no bug [TC 11.00b6] /W parameter for cm_commands does not always work

Post by *petermad »

Looks good :-)
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Post Reply