Button Parameter "%Q"

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Button Parameter "%Q"

Post by *Balderstrom »

There are a number of characters that are legal within a filename yet cause problems when parsing them within cmd batch scripts. These problematic characters (including <space>, &, ^ and others) can be handled by wrapping the string/filename in quotes.

I have found that TC provides no way to cleanly quote selected files, as it interferes with its internal quoting mechanism -- which it does if the file contains a space. If you attempt to do something like "%S" in a parameters field, it just puts quotes around the whole list (beginning and end).

It would be nice if perhaps the %Q parameter could be added, which functionally would force TC to quote each item individually regardless of any space in the path or filename in question.

So, if __FOO.txt, __List&File1.txt and __res ult.txt were selected
The Parameter: %Q%S
would produce the output:
"__FOO.txt" "__List&File1.txt" "__res ult.txt"


If it was placed in the parameters field a second time, the forced quoting would stop, a third time, resume, etc.

E.G. Parameters: %Q%S %Q%P %Q%T
[ Quote the selected files, don't quote the Path, quote the Target. ]

Or if it would make more sense, only have the %Q affect the parameter directly after it (not separated by any spaces).

E.G. Parameters: %Q%S %P %Q%T

Thanks.
Last edited by Balderstrom on 2016-07-31, 21:44 UTC, edited 1 time in total.
User avatar
sqa_wizard
Power Member
Power Member
Posts: 3864
Joined: 2003-02-06, 11:41 UTC
Location: Germany

Post by *sqa_wizard »

Support ++ for a consistent handling of filenames.

Meanwhile you can handle the parameter at your batch like this:

Code: Select all

Set MyFilename=%~1
echo "%MyFilename%"
This will initially remove the doublequotes (if any) of the first parameter (%1) and you can add them again if needed.
#5767 Personal license
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Doesn't work when the file has an ampersand "&" in it's name because the filename gets passed without any quotes, thus gets interpreted as a cmd "action" instead of part of a filename. Among other quirks/problems that creep in when you have special-chars in filenames -- like brackets () among others.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
User avatar
sqa_wizard
Power Member
Power Member
Posts: 3864
Joined: 2003-02-06, 11:41 UTC
Location: Germany

Post by *sqa_wizard »

I see :oops:
#5767 Personal license
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

I think some little tool may be used to quote all parameters w/o quotes - and it seems that it shouldn't be a CMD file but EXE (Windows will pass command line w/o changes to it).
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

That may be possible MVV, I'm sure I could pass all the arguments in question to AutoHotKey, and then pass them back to a CMD.exe instance. But then what is the point of passing it back to CMD.exe? I might as well just do the script in AHK.

And sometimes it's nice to actually get an improvement/clean-up/logical performing feature to TC without having to implement yet another little tool -- that only a handful of people will even realize is possible.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

The Little tool I use is AHK as an intemediary to any Batch scripts now.

TC_QuoteSelected.ahk

Code: Select all

   #SingleInstance, Force 
   #NoEnv 
SetBatchLInes, -1 

ControlGetFocus, activeControl, A 
if( (TC_GetCursorPosition( activeControl )) == 1 ) 
   fileList := "" 
else 
{ 
   ClipBoardBAK := "" 
   WinWaitActive, ahk_class TTOTAL_CMD 
   if( ClipBoard ) 
   { 
      ClipBoardBAK := ClipBoard 
      ClipBoard := "" 
   } 
   PostMessage, 0x433, 2017 ; cm_CopyFileNamesToClip 
   ClipWait 
   StringReplace, fileList, ClipBoard, `r`n, `"%A_Space%`", All 
   fileList = "%fileList%" 
   ClipBoard := "" 
   if( ClipBoardBAK ) 
   { 
      ClipBoard := ClipBoardBAK 
      ClipWait 
   } 
   ;MsgBox, 1: %1% :: 2: %2% :: fileList: %fileList% 
} 
Run, %comspec% /s /c ""%1%" "%2%" %fileList%",, Min 
return
Called from a Button with:
Command: %AHK%\TC_QuoteSelectedArgs.ahk CMDSCriptName.cmd" AnyOtherArgs

AHK gets the selected files from CLIP, after telling TC to copy them there. Quotes all of them, and passes them off to %comspec% (cmd.exe).

Though it would be lovely to not have to do that :-)

%AHK% is set in the RunTC.cmd that launches Total Commander.
---> AHK="F:\Program Files\AutoHotKey\AutoHotkey.exe" "F:\Program Files\AutoHotKey\Scripts"

Although that intemediary snippet will change, as I have a much cleaner way of doing Post/Send message now.
User avatar
chrizoo
Senior Member
Senior Member
Posts: 349
Joined: 2008-03-12, 02:42 UTC

Re: Button Parameter "%S"

Post by *chrizoo »

Balderstrom wrote: Or if it would make more sense, only have the %Q affect the parameter directly after it (not separated by any spaces).

E.G. Parameters: %Q%S %P %Q%T
ok, it's an interesting idea per se, but I don't really get it ...
... what is the difference between, say %Q%N and "%N" ?

Why can't I just quote the filename regardless of wether it's needed or not.
"%N" expands to
"some filename here.ext" ... which is fine
and
"filename.ext" .... which also doesn't do any harm, does it?

what I mean is:
why don't we quote everything just in case?
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

When you use %S (source panel) and %R (target panel) you get a List of files, not just where the cursor is currently.

When dealing with batch script, and a list of files, for safety and reliability purposes you want each item/filename/path to be quoted --- irrespective of spaces.

Thus you would want something like I noted in the OP:
%Q%P%S, or %Q%T%R

As I noted above, if you manually quote, then it is a single quote added to the LIST of files, and then if there happens to be a file that has spaces that gets quoted... then the cmd batch script interprets between the quotes and turns the whole thing into a mess.

The only option is to use a non-cmd batch intemediary, as even with TC's %L (feed to tmp file) the quote mechanism is still broken --- and you will be unable to parse such a file that has ampersands "&", brackets and other "special chars".

As well I certainly don't want to write to the disk every time I need a file list. An internal message or clipboard works fine for those purposes. Although neither work without a non-cmd tool to force quotes.

Something that TC should do internally, as there is no scripting language provided with TC.

This issue just makes dealing with batch script unpredicatble and more difficult than it needs to be.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Support for %Q modifier for command line parameter. Don't think it is too hard to realize.
User avatar
chrizoo
Senior Member
Senior Member
Posts: 349
Joined: 2008-03-12, 02:42 UTC

Post by *chrizoo »

.
seems like a no-brainer to me (not necessarily the implementation, but the question whether or not it is crucial for TC).

Has Mr. Ghisler commented on the issue yet or not?
User avatar
chrizoo
Senior Member
Senior Member
Posts: 349
Joined: 2008-03-12, 02:42 UTC

Post by *chrizoo »

.
I really think it is not necessary to introduce a whole set of new parameters with non-intuitive/unrelated letters which the TC user has to learn.

It would be sufficient and much more elegant to just use the EXISTING variables combined with a modifier character (").

I written a request for enhancement based on this idea here: http://ghisler.ch/board/viewtopic.php?t=30669
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

I think %Q%P or %QP is much easier to understand than %"P". And not so confusing.
User avatar
chrizoo
Senior Member
Senior Member
Posts: 349
Joined: 2008-03-12, 02:42 UTC

Post by *chrizoo »

^
Each to their own.
I think the important thing is that *some* solution is picked.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

2 year bump.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
Post Reply