When passing the parent path, an extra quote is added to the argument.

English support forum

Moderators: Hacker, petermad, Stefan2, white

Mapaler
Junior Member
Junior Member
Posts: 17
Joined: 2022-01-29, 06:05 UTC

Re: When passing the parent path, an extra quote is added to the argument.

Post by *Mapaler »

white wrote: 2025-04-02, 12:01 UTC
Help wrote:%P causes the source path to be inserted into the command line, including a backslash (\) at the end.
When the parent entry ".." is selected, %S produces no result, leaving the path with a trailing backslash.
Looks like that's why I'm having this issue.
white wrote: 2025-04-02, 12:01 UTC The parent entry in TC is handled in a special way. It sometimes means parent folder, and other times current folder. When %P is directly followed by %S, %N, or similar placeholders that turn out to be empty (when the parent entry is selected), it might be useful if TC would remove the trailing backslash from %P. Alternatively, it might be useful if TC would return the value ".." or "." for the %S, %N, or similar placeholders.
How do I get %P%S in the "folder" and ".." to keep the same result?

A lot of times I like to choose ".." to invoke a third-party program to open the current folder. Not all software takes into account removing quotation marks at the end.
Fla$her
Power Member
Power Member
Posts: 2981
Joined: 2020-01-18, 04:03 UTC

Re: When passing the parent path, an extra quote is added to the argument.

Post by *Fla$her »

Mapaler wrote: 2025-04-02, 12:30 UTC A lot of times I like to choose ".." to invoke a third-party program to open the current folder.
Use %P:~,-1 instead of %P%S.
Mapaler wrote: 2025-04-02, 12:30 UTC Not all software takes into account removing quotation marks at the end.
You've already been advised to use %Q.
Overquoting is evil! 👎
sa16
Senior Member
Senior Member
Posts: 324
Joined: 2021-09-10, 07:15 UTC

Re: When passing the parent path, an extra quote is added to the argument.

Post by *sa16 »

2Mapaler
So did not try? "%Q%P%S "
Mapaler
Junior Member
Junior Member
Posts: 17
Joined: 2022-01-29, 06:05 UTC

Re: When passing the parent path, an extra quote is added to the argument.

Post by *Mapaler »

Fla$her wrote: 2025-04-02, 12:47 UTC You've already been advised to use %Q.
sa16 wrote: 2025-04-02, 12:51 UTC 2Mapaler
So did not try? "%Q%P%S "
Thank you!

I thought this was just removing the quotes, and if I added the quotes back, it would also be escaped by the slash. Didn't expect to add a space at the end.
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: When passing the parent path, an extra quote is added to the argument.

Post by *beb »

Mapaler wrote: 2025-04-01, 11:14 UTC ..
Set a button text.exe in the toolbar and the parameter is %P%S
Choose parent path (⇧..) and click the button.
...
How to solve this problem?
2Mapaler

Honestly, both are a joke, from my point of view (in this context, and mostly anywhere else), and, luckily, both can be easily overridden:
[..] - you can still extract actual info from that, as seen from the script below.
%P%S - just abandon it and use something like %WL instead*, as seen from the script below.

*Note: %WL-like list will give you the pure path(s) of a file under the cursor/all the selected files without any unpredictable quote marks.

User-command (usercmd.ini):

Code: Select all

[em_test_tc_params_ps1]
cmd=pwsh -c "%commander_path%\Plugins\app\PowerShell\echoParams.ps1"
param=%WL %N %P %P%N %S %P%S %T %C1 %C2
PowerShell script (echoParams.ps1):

Code: Select all

if ($pwd){
'current and parent path'|Write-Host -f DarkGray;$pwd|Write-Host;$pwd|split-path} else {
'current directory cannot be detected...'|Write-Host -f Red}
''
if (-not($args)){
'No Total Commander arguments have been passed...'|Write-Host -f Red}
if ($args){
'Total Commander arguments breakdown...'|Write-Host -f Green
''
'first parameter as %WL (list file and its contents)'|Write-Host -f Yellow
$args[0]|Write-Host -f Cyan
foreach ($line in [IO.File]::ReadLines($args[0])){$line|Write-Host -f DarkCyan}
''
'raw $args array'|Write-Host -f Yellow
$args -join ' '|Write-Host -f DarkGray
''
'parameters by individual indexes [0]...[8]'|Write-Host -f Yellow
'[0] %WL  : {0}' -f $args[0]
'[1] %N   : {0}' -f $args[1]
'[2] %P   : {0}' -f $args[2]
'[3] %P%N : {0}' -f $args[3]
'[4] %S   : {0}' -f $args[4]
'[5] %P%S : {0}' -f $args[5]
'[6] %T   : {0}' -f $args[6]
'[7] %C1  : {0}' -f $args[7]
'[8] %C2  : {0}' -f $args[8]
''
'all {0} entries from $args array (recognized as separate items)' -f $args.count|Write-Host -f Yellow
$index = 0
foreach ($param in $args){
'{0,-8:[0]} : {1}' -f $index,$param;$index++}
}
''
pause
Video illustration:
Image: https://i.imgur.com/0TEWx1g.mp4

Explanation regarding current directory: even though the TC passes nothing via its 'so called parameters' (such as %P%S,%WL or wharever) when the cursor is on the '[..]' thing, the current active TC directory remains known for the PowerShell via the $pwd automatic variable, from which we can define whatever we want, e.g. parent directory as $parent = $pwd|split-path.

Explanation regarding %WL processing: %WL-like entity is the temporary list file that consists of lines where each line represents a file under the cursor/each of the selected files (their full names). Therefore, it can be processed as an array of lines (essentially, an array of files' full names), line by line (essentially, file by file): e.g. read as such via [IO.File]::ReadLines(%WL), and then, in its turn, processed individually, e.g. via the foreach ($line in [IO.File]::ReadLines(%WL)){"do something with that $line"} procedure).

Edit: a shorter version of the script.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Post Reply