Button Parameter "%Q"
Moderators: Hacker, petermad, Stefan2, white
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
Button Parameter "%Q"
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.
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.
- sqa_wizard
- Power Member
- Posts: 3869
- Joined: 2003-02-06, 11:41 UTC
- Location: Germany
Support ++ for a consistent handling of filenames.
Meanwhile you can handle the parameter at your batch like this:
This will initially remove the doublequotes (if any) of the first parameter (%1) and you can add them again if needed.
Meanwhile you can handle the parameter at your batch like this:
Code: Select all
Set MyFilename=%~1
echo "%MyFilename%"
#5767 Personal license
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
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.
- sqa_wizard
- Power Member
- Posts: 3869
- Joined: 2003-02-06, 11:41 UTC
- Location: Germany
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
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.
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.
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
The Little tool I use is AHK as an intemediary to any Batch scripts now.
TC_QuoteSelected.ahk
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.
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
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.
Re: Button Parameter "%S"
ok, it's an interesting idea per se, but I don't really get it ...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
... 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?
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
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.
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.
.
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
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
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC