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?
2
Mapaler
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.