Can batch file affect TC's current dir?

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
wanderer
Power Member
Power Member
Posts: 1571
Joined: 2003-03-28, 14:35 UTC
Location: Sol

Can batch file affect TC's current dir?

Post by *wanderer »

Lets say a folder's contents are shown in TC. One of the files is a batch. Can it contain a special CD command (i.e. TC-CD) which will change TC's directory?
- Wanderer -

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Normally using latest TC on:
x32: WinXPx32 SP3
x64: Clients/Servers from Win7 to Win11 and Win2K12Srv to Win2K22Srv, mainly Win10 though.
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6449
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Can batch file affect TC's current dir?

Post by *Horst.Epp »

Your batch can start TC again with the /o parameter and the path to the new dir you want.
Examples:
%COMMANDER_EXE% /O /L=path_for_left /R=path_for_right
or
%COMMANDER_EXE% /O /S path_for_active path_for_passive
Windows 11 Home x64 Version 23H2 (OS Build 22631.3374)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69
QAP 11.6.3.2 x64
User avatar
wanderer
Power Member
Power Member
Posts: 1571
Joined: 2003-03-28, 14:35 UTC
Location: Sol

Re: Can batch file affect TC's current dir?

Post by *wanderer »

Nope, thanks for the idea but i don't want to achieve that. Sometimes in some folders i have text files containing info about files in other folders. I thought it would be nice to transform them to batch files to change TC's panel to that folder...
- Wanderer -

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Normally using latest TC on:
x32: WinXPx32 SP3
x64: Clients/Servers from Win7 to Win11 and Win2K12Srv to Win2K22Srv, mainly Win10 though.
User avatar
white
Power Member
Power Member
Posts: 4593
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: Can batch file affect TC's current dir?

Post by *white »

wanderer wrote: 2023-03-08, 11:29 UTC I thought it would be nice to transform them to batch files to change TC's panel to that folder...
How is Horst.Epp's suggestion not accomplishing that?
User avatar
wanderer
Power Member
Power Member
Posts: 1571
Joined: 2003-03-28, 14:35 UTC
Location: Sol

Re: Can batch file affect TC's current dir?

Post by *wanderer »

I'd like to somehow execute the batch file and change the folder of the active panel of the current TC instance. :)
- Wanderer -

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Normally using latest TC on:
x32: WinXPx32 SP3
x64: Clients/Servers from Win7 to Win11 and Win2K12Srv to Win2K22Srv, mainly Win10 though.
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Can batch file affect TC's current dir?

Post by *petermad »

2wanderer
I'd like to somehow execute the batch file and change the folder of the active panel of the current TC instance
And that what the /O parameter accomplishes:

Put:

Code: Select all

%COMMANDER_EXE% /O /S drive:\path
in the first line of your .bat file.


Help wrote:/O If Total Commander is already running, activate it and pass the path(s) in the command line to that instance (overrides the settings in the configuration dialog to have multiple windows).
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
beb
Senior Member
Senior Member
Posts: 430
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Can batch file affect TC's current dir?

Post by *beb »

Example #1: an approach based on the loadlist command:
Try this (button for a button bar):

Code: Select all

TOTALCMD#BAR#DATA
loadlist
%P%N
wciconex.dll,0



-1
Explanation:
If a file under cursor (%P%N) contains any valid files/folders you will see a list of them in an active panel ready for further opening/browsing

Edit

Example #2: an approach based on the above-mentioned command (see @petermad's message):

Code: Select all

%COMMANDER_EXE% /O
Let's say we have a text file with a valid file/folder name in it, e.g.
test.txt

Code: Select all

%commander_path%\Language
then let's put a batch command in wincmd.ini:

Code: Select all

[em_test]
cmd=%comspec% /v /c for /f %f in (test.txt) do set folder=%f & %COMMANDER_EXE% /O=!folder!
then let's put it as a button in a button bar:

Code: Select all

TOTALCMD#BAR#DATA
em_test

wciconex.dll


0
10034
then being in a directory of test.txt tap the above button.
Result:
"%commander_path%\Language" folder from "test.txt" will be opened in the Total Commander target panel.

Edit 2

Limitations:

Approach #1: none
All you need just a file under cursor that as you know contains valid files/folders names
Other [than valid file/folders names] data in the file will be ignored (you'll just see a correspondent massage).

Approach #2:

- If the test.txt's file name is unknown you would have to parse it doing something like that:

Code: Select all

cmd=%comspec% /v /c for /f "tokens=* delims=" %f in ('dir /b/a/s ^| find /i ".txt"') do set file=%f & for /f %f in (!file!) do set folder=%f & %COMMANDER_EXE% /O=!folder!
- If the test.txt contains other text data you would have to parse it to extract only valid files/folders names by doing at least something like that (assuming ":\" part is one of a valid files/folders name):

Code: Select all

for /f "tokens=* delims=" %i in ('find ":\" "test.txt"') do echo %i
NB this won't work for the above test.txt content since %commander_path%\Language is swallowing ":\", and only "\" remains available.

- If the test.txt contains more than one valid file/folder name entry, you would rather need somehow to choose which one of them to pass to the Total Commander
Last edited by beb on 2023-03-08, 17:03 UTC, edited 6 times in total.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
User avatar
wanderer
Power Member
Power Member
Posts: 1571
Joined: 2003-03-28, 14:35 UTC
Location: Sol

Re: Can batch file affect TC's current dir?

Post by *wanderer »

2petermad
2beb

Thank you both the the interesting ideas! I'll try them, and first of all the /O one, which seems most promising.

2Horst.Epp
I just understood that your post was doing just that! Thanks!
- Wanderer -

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Normally using latest TC on:
x32: WinXPx32 SP3
x64: Clients/Servers from Win7 to Win11 and Win2K12Srv to Win2K22Srv, mainly Win10 though.
Post Reply