batch-filebatch-processingtotal-commander

How to open folder with an already running Total Commander in BATCH?


I want to create a BATCH file, which opens a specified folder with Total Commander. But there are 2 possibility:

  1. if there is no running TotalCommander --> a new TotalCommander will start and open the folder
  2. if there is an already running TotalCommander --> open the folder with the running TC, and do not start a new TotalCommander

I have a code, which opens the folder with TotalCommander, but it always start a new TotalCommander, and not using the running one:

@echo off
SET totalc="C:\totalcmd\TOTALCMD.EXE"
set folder="C:\temp"
ECHO opening %folder% with %totalc%
%totalc% %folder%
ECHO opened

Is there any solution, to resolve this?


Solution

  • @echo off
        setlocal
        set "totalc=C:\totalcmd\TOTALCMD.EXE"
        set "folder=C:\temp"
        echo opening "%folder%" with "%totalc%"
        "%totalc%" /O /T /R="%folder%"
        echo opened
    

    From the documentation

    /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)

    /R= Set path right window

    /T Opens the passed dir(s) in new tab(s) (for usage with /O)