I've started using the variable %COMMANDER_PATH% in my batch files, it's makes portability now much easier than typing the whole path which was different from every machine/OS I've got.
But something puzzles me, my batch files recognise the variable, the command prompt built into TC (cm_ExecuteDOS) also recogises it, but using C:\WINDOWS\system32\cmd.exe and typing 'ECHO TC commander Path is %COMMANDER_PATH%' it doesn't recognise it, it just returns TC commander Path is %COMMANDER_PATH% message.
And how can this be global? I mean I cannot find the term anywhere %COMMANDER_PATH% in the system registry.
%COMMANDER_PATH% question
Moderators: Hacker, petermad, Stefan2, white
Hello, Spiderkeys.
The Variable %COMMANDER_PATH% will be set by Total Commander itself when starting up. As a consequence only Total Commander itself and all the processes which Total Command spawns will know the variable %COMMANDER_PATH%.
In case, however, you launch the Windows command prompt from outside Total Commander, e.g. from the Windows application start menu or by using <WinKey>R and typing "cmd.exe", then this incident of cmd.exe will have no knowledge of the variable %COMMANDER_PATH%, because it is not a child process of Total Commander.
Cheers,
Karl
The Variable %COMMANDER_PATH% will be set by Total Commander itself when starting up. As a consequence only Total Commander itself and all the processes which Total Command spawns will know the variable %COMMANDER_PATH%.
In case, however, you launch the Windows command prompt from outside Total Commander, e.g. from the Windows application start menu or by using <WinKey>R and typing "cmd.exe", then this incident of cmd.exe will have no knowledge of the variable %COMMANDER_PATH%, because it is not a child process of Total Commander.
Cheers,
Karl
-
- Junior Member
- Posts: 53
- Joined: 2015-04-07, 10:02 UTC
Ahh, now i'm beginning to get it, about 95% of my batches are always launched within TC, and very few are launched from Scheluded Tasks or desktop. Just dragged one from TC from to desktop, and as expected as reading above, it didn't work.
Still handy, just got to think before I write a script, if I've been ever needing to launch it outside TC, then obviously the full paths would then be required.
Or maybe use the SET command at the start of those scripts just to be sure.
Still handy, just got to think before I write a script, if I've been ever needing to launch it outside TC, then obviously the full paths would then be required.
Or maybe use the SET command at the start of those scripts just to be sure.
IF NOT defined Commander_Path Exit
If you want you can check if a variable is defined.Spiderkeys wrote:Or maybe use the SET command at the start of those scripts just to be sure.
Examples:
Code: Select all
@ECHO OFF
IF NOT defined Commander_Path Exit
REM else:
ECHO I'm still here and do my stuff now...
rem
rem
rem
- - - or:
Code: Select all
@ECHO OFF
Setlocal EnableDelayedExpansion
if defined Commander_Path (
ECHO TC-Path is set already to: %Commander_Path%
ECHO All fine, will go on...
) else (
ECHO Commander_Path var is not defined yet!
SET /P TCPATH="Enter path to TC-folder (or x to close):"
IF !TCPATH!==x Exit
IF [!TCPATH!]==[] Exit
SET Commander_Path=!TCPATH!
ECHO TC-Path is set now to: !Commander_Path!
ECHO Everything is fine now, will go on...
)
ECHO Do your stuff here:
rem
rem
rem
rem All done!
PAUSE
-
- Junior Member
- Posts: 53
- Joined: 2015-04-07, 10:02 UTC
Thats very clever Stefan2, I prefer your second example more, even still if it comes to worse, I only need to type out the path once and not 50 times when it came to very long scripts.
A batch file which would work nearly perfectly on one OS, move it another required changing paths to TC, and always I missed one somewhere, now I only need to pay attention to check if variable is defined on top of each script.
A batch file which would work nearly perfectly on one OS, move it another required changing paths to TC, and always I missed one somewhere, now I only need to pay attention to check if variable is defined on top of each script.
I'm using another approach: launch TC via batch file which is located in the same path as totalcmd.exe, like this:So the %~dp0 is equal to %COMMANDER_PATH%. To automate this, and to be able to use the variable before launching TC, you could do something like this:
somewhere in the first couple lines.
Be careful, though, as %~dp0 includes the trailing backslash!
Regards
Dalai
Code: Select all
start /wait "Total Commander" "%~dp0totalcmd.exe"
Code: Select all
if "%COMMANDER_PATH%"=="" set COMMANDER_PATH=%~dp0
Be careful, though, as %~dp0 includes the trailing backslash!
Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64
Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror