Change directory with relative path

English support forum

Moderators: Hacker, petermad, Stefan2, white

liamZ
Junior Member
Junior Member
Posts: 23
Joined: 2014-12-28, 20:04 UTC

Change directory with relative path

Post by *liamZ »

Hi, I'm trying to find a method to change directory with relative path.
Is there an easy way?

I know if a run on the tab command line:

cd ..\..\mydir

it changes the current dir of that panel to mydir.

A possible solution would be to pass a cmd file to run like it is written directly on that command line.

Any ideas?

Thanks.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

If you run that cmd file from buttonbar, you can use %P and %T, and TC will expand them to current path of active or inactive panel.
liamZ
Junior Member
Junior Member
Posts: 23
Joined: 2014-12-28, 20:04 UTC

Post by *liamZ »

Hi, thanks for your answer. Can you explain it a little more?

Run a cmd file from the button bar? By %P, %T you mean /T, /P?


Thanks.
User avatar
sqa_wizard
Power Member
Power Member
Posts: 3896
Joined: 2003-02-06, 11:41 UTC
Location: Germany

Post by *sqa_wizard »

Just create a button at your buttonbar with this command.

Simply copy the below text and paste it at your buttonbar.
It will create an according button.

Code: Select all

TOTALCMD#BAR#DATA
cd ..\..\mydir

%COMMANDER_PATH%\TOTALCMD.EXE,1



-1
#5767 Personal license
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

It is much easier just to create a button with command cd ..\..\mydir 'cause it is an internal TC command.
liamZ
Junior Member
Junior Member
Posts: 23
Joined: 2014-12-28, 20:04 UTC

Post by *liamZ »

[quote="sqa_wizard"]Just create a button at your buttonbar with this command.

Simply copy the below text and paste it at your buttonbar.
It will create an according button.
[code]TOTALCMD#BAR#DATA
cd ..\..\mydir

%COMMANDER_PATH%\TOTALCMD.EXE,1



-1[/code][/quote]


Thanks for your answer, I understand what you mean, but what I want is something to do with a lot of directories, not just with one. I want this for my portable USB programs.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Please describe exactly what do you want, we'll try to answer how to do that.
liamZ
Junior Member
Junior Member
Posts: 23
Joined: 2014-12-28, 20:04 UTC

Post by *liamZ »

Hi, What I want is to create something like a shortcut with relative path to directories. That's not possible on Windows shortcuts, so I want to know if there's a way to do something similar with TotalCommander:

I'm in a directory ?:\portables\system\

and I want to change to ?:\portables\Internet\Hist\

double clicking on some kind of shortcut.

Thanks.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

You can use internal cd command in buttonbar or in directory hotlist (Ctrl+D or asterisk button above panel).
If your portables folder is in drive's root, it is better to use command like cd \portables\Internet\Hist\, or maybe even cd %COMMANDER_DRIVE%\portables\Internet\Hist\, if this folder is on same drive with TC. You can add any number of such entries to directory hotlist and access them using mouse or keyboard.
liamZ
Junior Member
Junior Member
Posts: 23
Joined: 2014-12-28, 20:04 UTC

Post by *liamZ »

Hi, thanks for your solution and your help, I didn't know about %COMMANDER_DRIVE%, but what i want is some kind of shortcut in the folder.
liamZ
Junior Member
Junior Member
Posts: 23
Joined: 2014-12-28, 20:04 UTC

Post by *liamZ »

OK, finally I found a first solution to this:

Creating a shortcut in "?:\Portables\System" with target:

"c:\Program Files\Totalcmd\TOTALCMD.exe" /O /S /L=%COMMANDER_DRIVE%\Portables\Internet\Hist


Cause this one doesn't work:

"c:\Program Files\Totalcmd\TOTALCMD.exe" /O /S /L=..\Internet\Hist

(and "START IN" blank)
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

liamZ wrote:"c:\Program Files\Totalcmd\TOTALCMD.exe" /O /S /L=%COMMANDER_DRIVE%\Portables\Internet\Hist
Sorry, that doesn't make any sense. Since you start Totalcmd.exe from C: the variable %COMMANDER_DRIVE% will always be C: or do you have two TC installations?

I'm still not sure what you're trying to accomplish. Do you start TC from a portable drive and you want to jump to folders on that drive?

You can use a variable in the link target:

%COMMANDER_DRIVE%\Portables\Internet\Hist

This works atleast with Win 8.1. From what I've read there was a problem that the variables get expanded right after you enter them but it works for me i.e. the variable stays a variable.
liamZ
Junior Member
Junior Member
Posts: 23
Joined: 2014-12-28, 20:04 UTC

Post by *liamZ »

Yes you're right, I think this will work:

C:\WINDOWS\system32\cmd.exe /c start /d"\Portables\totalcmd" /b TOTALCMD.EXE /O /S /L=%COMMANDER_DRIVE%\Portables\Internet\Hist


For me the %COMMANDER_DRIVE% does not work out of TotalCMD.
liamZ
Junior Member
Junior Member
Posts: 23
Joined: 2014-12-28, 20:04 UTC

Post by *liamZ »

[quote="ZoSTeR"]
I'm still not sure what you're trying to accomplish. Do you start TC from a portable drive and you want to jump to folders on that drive?
[/quote]

Yes, taht's what I want. I plug my usb on a computer and execute TC from it and quickly jump to directories in that usb drive.
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

You can set a global variable with SetX. Create a cmd file on your portable drive with:

Code: Select all

setx _portable_drive %~d0
and run it as admin.

The variable %_portable_drive% will be available to all processes started after that. Make sure you clean up the variable when you're done via the GUI (see link).
Post Reply