[solved] How to open a parallel path within a structure seeing the target path of its sister structure?

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

[solved] How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *beb »

Example input data:
the root folder of the first parallel/sister structure is:
"d:\structure"
the root folder of the second parallel/sister structure is:
"x:\cloud\backup\structure"
The child content of both sister structures is implied to be identical.
The differences in paths are put in red, the identical parts are blue.

Goal:
Being within the first structure (opened in the TotalCommander active pane), let's say under the active path:
"d:\structure\level\sublevel"
I switch to the other pane and the above path becomes the target.
Now I want a parallel folder within the sister structure to be opened (in the TotalCommander now active pane) regarding the target.
So, the new active pane path should become as follows:
"x:\cloud\backup\structure\level\sublevel"

My approach:
- the target path in TotalCommander is represented by the %T variable.
- I take %T, skip its 2 characters, and then extract everything else, which should fall into syntax: %T~2
so, while %T returns: "d:\structure\level\sublevel\",
the %T~2 should return: "\structure\level\sublevel\",
- Then I take the part of a sister path that differs: "x:\cloud\backup"
- Those two together ("x:\cloud\backup" and %T~2) should give the desired result: x:\cloud\backup\structure
The final command is:

Code: Select all

cd x:\cloud\backup%T~2
or could be (if you want):

Code: Select all

cd x:\cloud\backup\%T~3
But it just does not work as intended.
So what I miss here.
What's the actual syntax?
Last edited by beb on 2024-10-26, 20:09 UTC, edited 2 times in total.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *beb »

I can make it in PowerShell, for instance, as simple as this:
user command:

Code: Select all

[em_tc_goToSister_ps1]
cmd=pwsh -c "%commander_path%\Plugins\app\PowerShell\tcGoToSister.ps1"
param=%T
tcGoToSister.ps1:

Code: Select all

& $env:commander_exe /o $args[0] ('x:\cloud\backup' + $args[0].substring(3))
or as a one-liner user command (without .ps1):

Code: Select all

[em_tc_goToSister]
cmd=pwsh -c
param=sv t -value %T;& $env:commander_exe /o $t ('x:\cloud\backup' + $t.substring(3))
But I'm still looking for a native way/command.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
white
Power Member
Power Member
Posts: 5747
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *white »

beb wrote: 2024-10-26, 11:00 UTC So what I miss here.
What's the actual syntax?
You are using parameter pseudo variables in the command field instead the parameter field. Move the parameter of the cd command to the parameter field.

It's only possible to use paramater variables in the command field when using them in paramaters of em_ commands while leaving the parameters field empty.
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *beb »

2white
Thanks, I know that.
The actual construction is as follows:

Code: Select all

TOTALCMD#BAR#DATA
cd
"x:\cloud\backup\%T:~3"
%commander_exe%



-1
The essence of the issue remains the same: how to get the substring of %T.
If I know the length of %T (let's say it is 27 characters), I can put it that way and it would work:

Code: Select all

TOTALCMD#BAR#DATA
cd
"x:\cloud\backup\%T:~3,27"
%commander_exe%



-1
But what to do if the length itself is variable?
How to extract the ending part of %T starting from a given character to the very end?
Looks as though TotalCommander does not understand "%T:~3" syntax which is a part of the standard approach to retrieve specific characters from a string variable in cmd.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
white
Power Member
Power Member
Posts: 5747
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *white »

beb wrote: 2024-10-26, 14:20 UTC But what to do if the length itself is variable?
I had noticed that too. That's why I suggested in another case to simply use a high number:
white wrote: 2024-09-25, 15:05 UTC ...
and use (for example) %A:~-0,1024 in the parameter field of the em_pdflatex command
Take a high number of your choice ;)
Or use -1 to cut off the backslash at the end.
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *beb »

Lol, I did it.
As I figured out, in TotalCommander "%T:~3" returns only one character, the first one of the remainder of the ":~3" removal operation (the fourth one in absolute count), so it's useless here.
It turns out, since %T includes the backslash (\) at the end, "%T:~3,-1"
does the trick:
"~3" removes the first three chars of the target path (which is "d:\" in my example)
"-1" removes the terminal char of the target path (which is always "\" and has no special value).
Thus, regarding the given example, "%T:~3,-1" here returns the desired usable reminder: "structure\level\sublevel"
So, the nearly* final working result is as follows:

Code: Select all

TOTALCMD#BAR#DATA
cd
"x:\cloud\backup\%T:~3,-1"
%commander_exe%
go to sister structure


-1
or (if you want):

Code: Select all

TOTALCMD#BAR#DATA
cd
"x:\cloud\backup%T:~2,-1"
%commander_exe%
go to sister structure


-1
* Note: They are "nearly final" because it works so far only if the path does not contain spaces.

Edit: strikethrough
Last edited by beb on 2024-10-26, 17:54 UTC, edited 2 times in total.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *beb »

white wrote: 2024-10-26, 15:19 UTC Or use -1 to cut off the backslash at the end.
Yes, it did the trick.
I saw it in the help "Example: %P:~0,-1 cuts off the backslash from the path." and tried.
Thank for your help and time.
There's still a step to go with those spaces, though.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
white
Power Member
Power Member
Posts: 5747
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *white »

beb wrote: 2024-10-26, 15:39 UTC * Note: They are "nearly final" because it works so far only if the path does not contain spaces.
What exactly is the problem if the path contains spaces?
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *beb »

2white
The command cannot handle the spaced paths.
If the remainder of "%T" contains a spaced entry the command follows the resulting path within the sister destination only until it meets the first space, i.e.:
target path:
"d:\structure\level\sublevel\prespaced\spa ced\postspaced\"
"%T:~3,-1" result:
"structure\level\sublevel\prespaced\spa ced\postspaced"
sister path:
"x:\cloud\backup\structure\level\sublevel\prespaced\spa ced\postspaced"

The command reaches only the "prespaced" level:
"x:\cloud\backup\structure\level\sublevel\prespaced"
but cannot enter the "spa ced" entry and get to the actual destination ("postspaced").


Edit: strikethrough
Last edited by beb on 2024-10-26, 16:51 UTC, edited 1 time in total.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
white
Power Member
Power Member
Posts: 5747
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *white »

beb wrote: 2024-10-26, 16:33 UTC The command reaches only the "prespaced" level:
"x:\cloud\backup\structure\level\sublevel\prespaced"
but cannot enter the "spa ced" entry and get to the actual destination ("postspaced").
That probably means the folder names are not the same. Perhaps one has 2 spaces?
BTW, when using the cd command, quotes can be left out as well (when not used in a list of multiple commands).
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *beb »

2white
Oh, my bad.
It works -- there was a mistake on my side.
Sorry.
The command does work as intended.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
User avatar
petermad
Power Member
Power Member
Posts: 16001
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *petermad »

2beb
Have you thought about using the cm_SyncChangeDir command once you are in "d:\structure" and "x:\cloud\backup\structure" - with this command activated both panels will update when you go down the levels under "d:\structure"
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
white
Power Member
Power Member
Posts: 5747
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *white »

petermad wrote: 2024-10-26, 16:59 UTC Have you thought about using the cm_SyncChangeDir command once you are in "d:\structure" and "x:\cloud\backup\structure" - with this command activated both panels will update when you go down the levels under "d:\structure"
Or combining it with the command "cm_SyncChangeDir 1" (and creating an em_ command for de cd thingy).
User avatar
beb
Power Member
Power Member
Posts: 579
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: How to open a parallel path within a structure seeing the target path of its sister structure?

Post by *beb »

2petermad,white
No. I had not. Yet. Until you've asked.
:)

As you can see, I picked a straight-forward track and followed it to the end for today.
Of course, tomorrow comes the other day...

Currently, the solutions 1-4:

[1,2] Native TotalCommander's (the fastest one) [a button]:

Code: Select all

TOTALCMD#BAR#DATA
cd
"x:\cloud\backup\%T:~3,-1"
%commander_exe%



-1
and/or

Code: Select all

TOTALCMD#BAR#DATA
cd
"x:\cloud\backup%T:~2,-1"
%commander_exe%



-1
[3] PowerShell .ps1 based [a user command]:

Code: Select all

[em_tc_goToSister_ps1]
cmd=pwsh -c "%commander_path%\Plugins\app\PowerShell\tcGoToSister.ps1"
param='"'%T'"'
Note the massively-quote-surrounded param='"'%T'"' as a workaround for the spaced paths.
Where tcGoToSister.ps1 is:

Code: Select all

& $env:commander_exe /o $args[0] ('x:\cloud\backup' + $args[0].substring(3))
[4] PowerShell one-liner based [a user command]:

Code: Select all

[em_tc_goToSister]
cmd=pwsh -c
param=sv t -value '%T';& $env:commander_exe /o $('"'+$t+'"') $('"'+'x:\cloud\backup' + $t.substring(3)+'"')
Note the single-quote-surrounded param= ... '%T' as a workaround for the spaced paths.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10/15
Post Reply