Custom command for switching between directories...
Moderators: Hacker, petermad, Stefan2, white
Custom command for switching between directories...
Hello.
I have no experience with creating my own commands, so I would need help. I can probably handle the user-command definition itself (usercmd.ini) and the connection to some keyboard shortcut. But I have no idea how to do the following:
I need to quickly switch (in the current panel) between "corresponding" dirs (will explain later). I would probably also use the option of switching in to the given path the 2nd panel, but that is a "nice to have" feature. I am working with a UE5 (Unreal Engine) projects and it has its source-files of any module divided into "Public" directory (*.h files) and "Private" directory (*.cpp). The tree structure underneath is more or less identical. And I would like to quickly switch between the corresponding sub-directories - if I am in the dir with *.h, then switch to the dir with corresponding *.cpp file and vice versa.
I suppose I should have some *.bat script that would output the path I want to switch to... but I don't know how to do it in TC. The script will travel "up" in the tree structure (remembering the relative path) until it is in a "root" directory with both "Public" and "Private" subdirectories, and then it will dive (into the same relative path) to the opposite of the one I came from.
Does anyone know how to do it? I'm talking about building the custom TC command itself using some *.bat file, which would receive the current panel's path as a parameter and, on the contrary, result in the path where to switch.
Thanks a lot for any "guidance".
Martin
I have no experience with creating my own commands, so I would need help. I can probably handle the user-command definition itself (usercmd.ini) and the connection to some keyboard shortcut. But I have no idea how to do the following:
I need to quickly switch (in the current panel) between "corresponding" dirs (will explain later). I would probably also use the option of switching in to the given path the 2nd panel, but that is a "nice to have" feature. I am working with a UE5 (Unreal Engine) projects and it has its source-files of any module divided into "Public" directory (*.h files) and "Private" directory (*.cpp). The tree structure underneath is more or less identical. And I would like to quickly switch between the corresponding sub-directories - if I am in the dir with *.h, then switch to the dir with corresponding *.cpp file and vice versa.
I suppose I should have some *.bat script that would output the path I want to switch to... but I don't know how to do it in TC. The script will travel "up" in the tree structure (remembering the relative path) until it is in a "root" directory with both "Public" and "Private" subdirectories, and then it will dive (into the same relative path) to the opposite of the one I came from.
Does anyone know how to do it? I'm talking about building the custom TC command itself using some *.bat file, which would receive the current panel's path as a parameter and, on the contrary, result in the path where to switch.
Thanks a lot for any "guidance".
Martin
Last edited by Capa79 on 2024-03-01, 11:26 UTC, edited 1 time in total.
Re: Custom command for switching between directories...
Create custom commands for directory change, e.g add such a lines to your USERCMD.INI
Bind keyboard shortcuts to both.
Code: Select all
[em_CDPublic]
cmd=CD ..\Public
[em_CDPrivate]
cmd=CD ..\Private
Re: Custom command for switching between directories...
Here user yozhic suggested the following BAT-file:
For example, such a button for it:
Code: Select all
@rem Script: test.bat
@rem Parameters: "%P" "\part of the path\" "\part of the path\"
@echo off
set go=%~1
call set go=%%go:%~2=%~3%%
if "%~1"=="%go%" (call set go=%%go:%~3=%~2%%)
%COMMANDER_EXE% /O /S "%go%"
Code: Select all
TOTALCMD#BAR#DATA
%COMMANDER_PATH%\CMD\test.bat
"%Z%P" "c:\Wincmd\" "d:\Wincmd_x64\"
wcmicons.dll,75
Replacing part of the path and navigating the modified path|c:\Wincmd <--> d:\Wincmd_x64
1
-1
Re: Custom command for switching between directories...
Thanks, but it won't be so easyGral wrote: 2024-03-01, 10:30 UTC Create custom commands for directory change, e.g add such a lines to your USERCMD.INIBind keyboard shortcuts to both.Code: Select all
[em_CDPublic] cmd=CD ..\Public [em_CDPrivate] cmd=CD ..\Private

But I found much easier way how the script for generating target path should work:
1) take current path
2) if it contains '\Public\' replace it with '\Private\' or
if it contains '\Private' replace it with '\Public'\
3) if modified path is valid (exists) "switch" to it... otherwise stay where you are
Re: Custom command for switching between directories...
2Capa79
There are several solutions here. If you need help with translation, we will provide it.
I advise you to pay attention to the last two codes.
There are several solutions here. If you need help with translation, we will provide it.
I advise you to pay attention to the last two codes.
Overquoting is evil! 👎
Re: Custom command for switching between directories...
So far I got here but it is still not working and I don't know why...
Custom command:
Content of the switch_ue5_src_dirs.bat:
Custom command:
Code: Select all
cmd=c:\switch_ue5_src_dirs.bat
params="%P"
Code: Select all
@echo off
setlocal
set "inputPath=%~1"
:: try to switch between 'Public' and 'Private'
echo %inputPath% | findstr /i "\\Public\\" > nul
if not errorlevel 1 (
set "newPath=%inputPath:\Public\=\Private\%"
goto verifyPath
)
echo %inputPath% | findstr /i "\\Private\\" > nul
if not errorlevel 1 (
set "newPath=%inputPath:\Private\=\Public\%"
goto verifyPath
)
::given path doesn't contain '\Public\' or '\Private\'
exit /b 1
:verifyPath
if exist "%newPath%" (
%COMMANDER_EXE% /O /S "%newPath%"
)
endlocal
Re: Custom command for switching between directories...
2Capa79
Above, I suggested using non-console js/vbs. Are there any difficulties?
Above, I suggested using non-console js/vbs. Are there any difficulties?
Overquoting is evil! 👎
Re: Custom command for switching between directories...
Oh... I can try to do it via Javascript. Have no experience, probably ChatGPT will help me
, but I would need something to allow me execute JScript in Win10, isn't it?

Re: Custom command for switching between directories...
2Capa79
I've already given you the solutions, you don't need ChatGPT. JScript on Win 98-11 should work. .js is the same executable file as .bat, but you need to save it in ANSI.
I've already given you the solutions, you don't need ChatGPT. JScript on Win 98-11 should work. .js is the same executable file as .bat, but you need to save it in ANSI.
Code: Select all
/*********************** JS **********************
Switch between two parts of a working folder path
Parameters: "%P" <Path part 1> <Path part 2>
Example: "%P" "\DirName 1\" "\DirName 2\"
*************************************************/
a = WSH.arguments
if(a(0).indexOf(a(1))>-1){i = 1; n = 2} else {if(a(0).indexOf(a(2))>-1){i = 2; n = 1} else WSH.quit()}
WSH.CreateObject('WScript.Shell').exec('%COMMANDER_EXE% /O0 /S "' + a(0).replace(a(i), a(n)) + '"')
Overquoting is evil! 👎
Re: Custom command for switching between directories...
Thank you @Fla$her. It worked work me... don't know why but I ended with 2nd and 3rd param (exchanged part of path) without quotation.
Otherwise I got "Subscript out of range" error.
Otherwise I got "Subscript out of range" error.
Re: Custom command for switching between directories...
2Capa79
Any parameters containing spaces must be in quotation marks. This applies to all parameterized programs.
Any parameters containing spaces must be in quotation marks. This applies to all parameterized programs.
Overquoting is evil! 👎