Environment variable for directory of wincmd.ini

Here you can propose new features, make suggestions etc.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
burg1
Junior Member
Junior Member
Posts: 30
Joined: 2007-07-10, 13:56 UTC

Environment variable for directory of wincmd.ini

Post by *burg1 »

Hi,

I'd like to suggest adding an environment variable for the directory in which wincmd.ini resides in.

Note: %COMMANDER_INI% gives the full path e.g. C:\tc\wincmd.ini but what I'd like to get is C:\tc

Reason: I'm using customized icons (in default.bar) and this would be a nice feature to easily transfer TC to another computer (and keeping those icon files).

Thanks!
Henrie
Member
Member
Posts: 194
Joined: 2006-09-03, 23:12 UTC
Location: Volkel, the Netherlands

Post by *Henrie »

%COMMANDER_PATH%
Since version 6.0 environment variable COMMANDER_PATH points to the Total Commander directory

And since version 7.0 %COMMANDER_DRIVE% points to drive (e.g. C: without trailing backslash) from which Total Commander was started.

Hip Hip Hooray, for my 100th post
User avatar
karlchen
Power Member
Power Member
Posts: 4605
Joined: 2003-02-06, 22:23 UTC
Location: Germany

Post by *karlchen »

Hello, Henrie. Hello, burg1.

%COMMANDER_PATH% points to the Total Commander programme folder. The file wincmd.ini may be stored there, but it need not.
Therefore %COMMANDER_PATH% cannot be used as a reliable way of pointing to the folder where %COMMANDER_INI% is located.
Much in the same way, %COMMANDER_DRIVE% only points to the drive where %COMMANDER_PATH% is located. %COMMANDER_INI% may or may not be stored on the same drive.

So neither %COMMANDER_DRIVE%, nor %COMMANDER_PATH% give any reliable hint where %COMMANDER_INI% may be found.

Yet, there is a dirty little trick which can do so, provided you do so inside Total Commander itself or inside a process which has enherited the Total Commander environment:
%COMMANDER_INI%\..
Note:
This seems to fail e.g. if you try to use it on Wine. It seems to work fine on Windows, however.

Summary:
burg1, you are right. Currently there is no T.C. internal variable which points to the folder where %COMMANDER_INI% is located. The same is true for the location of wcx_ftp.ini. There is no T.C. internal variable which points to its folder. It would be nice to have such environment variables though.

Kind regards,
Karl
Henrie
Member
Member
Posts: 194
Joined: 2006-09-03, 23:12 UTC
Location: Volkel, the Netherlands

Post by *Henrie »

Hello karlchen,

Burg1 gave an example
burg1 wrote:Note: %COMMANDER_INI% gives the full path e.g. C:\tc\wincmd.ini but what I'd like to get is C:\tc
Therefore i thought the variable %COMMANDER_PATH% would suffice in his case.

%COMMANDER_DRIVE% I just put in there because it is fairly new and is handy in case one likes to use a portable TC.

Regards,
Henrie
User avatar
karlchen
Power Member
Power Member
Posts: 4605
Joined: 2003-02-06, 22:23 UTC
Location: Germany

Post by *karlchen »

Hello, Henrie.

You are absolutely right, in Burg1's example %COMMANDER_INI% is stored inside the T.C. programme folder. Therefore in this special case, %COMMANDER_PATH% holds the fully qualified foldername of the folder where %COMMANDER_INI% lives.

I had tried to explain that this were a special case and that %COMMANDER_INI% need not even be stored on the same drive as the Total Commander programme folder.

Kind regards,
Karl
burg1
Junior Member
Junior Member
Posts: 30
Joined: 2007-07-10, 13:56 UTC

Post by *burg1 »

Hi everybody,

sorry for the bad example!

What I mean is:
If the full path is C:\abc\wincmd.ini, I'd like to get C:\abc

@karlchen:
Thanks for the %COMMANDER_INI%\.. workaround, I'll give it a try!

Cheers!
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Please see, Setting Environment Variables | Passing Vars between Apps

You can set additional permanent Environment variables, such as you want - the command in question only needs to be run once per machine.

Eg, all of this used to be in the .cmd I use to launch TC, now I ran it once and added them as User Environment Variables:

Code: Select all

@ECHO OFF
:: SET PATH=%SYS32%;C:\WIN2K;%wuBIN%;%wuBin%\exCMD;%wuBIN%\exDOS;%SYS32%\Wbem
SETENV -u AHKDir "%ProgramFiles%\AutoHotKey"
SETENV -u AHKICO "%AHKDir%\AutoHotkey_AHK1.icl"
SETENV -u AHK "\"%AHKDir%\AutoHotkey.exe\" \"%%AHKDir%%\Scripts\""
SETENV -u AppAccess "%ProgramFiles%\Accessories"
SETENV -u APPLOCAL "%USERPROFILE%\Local Settings\Application Data"
::
::	Applications
::		\Program Files\$CATegory
::
SET count=0
CD %ProgramFiles%
FOR /F "usebackq delims=?" %%F IN (`dir /a:d /o:n /b` ) DO CALL:_SET_PARENT_FOLDERS "%%F"
SETENV -u AppAccess "%ProgramFiles%\Accessories"
::
::	Applications
::		\Program Files\$Graphics\$__SubCat  
::
SET count=0
CD "%AppGraphics%"
FOR /F "usebackq delims=?" %%F IN (`dir /a:d /o:n /b` ) DO CALL:_SET_GRAPHIC_FOLDERS "%%F"

SETENV -u TC "%ProgramFiles%\TotalCMD"
SETENV -u TCmd "%TC%\TotalCMD.exe"
SETENV -u TCDATA "%APPDATA%\_TC_"
SETENV -u TCTOOL "%wuBIN%\TCTools"
SETENV -u TCMC "%TCTOOL%\TCMC.exe 50"
:: junction -d "%TC%\Data"
:: junction "%TC%\Data" "%TCDATA%"
SET count=
SET tmpF=
GOTO:EOF
::
:: Workaround for CMD.exe limitation: Refuses to properly SET a variable that contains characters such as: ¤ or § 
:: -- ( If the string is retrieved from a DIR command)
:: -- eg: %ProgramFiles%\¤Graphics
::
:: Yet I have found it _does_ SET the proper variable from %CD% ...
::
:_SET_PARENT_FOLDERS
SET /A count=%count% + 1
IF %count% GTR 7 GOTO:EOF
SET "tmpF=%~1"
SET "tmpF=%tmpF:~1%"
PUSHD "?%tmpF%"
SETENV -u App%tmpF% "%CD%"
POPD
GOTO:EOF
::
:: Likewise, above: CMD.exe will not SET a variable that contains: § 
:: -- such as %ProgramFiles%\¤Graphics\§__Image_View
::
:_SET_GRAPHIC_FOLDERS
SET /A count=%count% + 1
IF %count% GTR 6 GOTO:EOF
SET "tmpF=%~1"
SET "tmpF=%tmpF:~1%"
PUSHD "?%tmpF%"
SET "tmpF=%tmpF:_=%"
SETENV -u "g%tmpF%" "%CD%"
POPD
::SET "g%tmpF%=%CD%\%~1"
GOTO:EOF
For instance, I use the TCDATA var for a lot of the Icon fields in the buttonBar:
Icon file: %TCDATA%\GUI\icons\mwmTotalCmd2.icl
Where TCDATA == %APPDATA%\_TC_
burg1
Junior Member
Junior Member
Posts: 30
Joined: 2007-07-10, 13:56 UTC

Post by *burg1 »

Hi Balderstrom,

thanks - looks cool!
But so far, the %COMMANDER_INI%\.. workaround is fine for me :-)

Cheers!
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

If you are using a command prompt you could do something like:

Code: Select all

::
:: TC_QueryINIPath.cmd
::
@ECHO OFF
FOR /F "delims=" %%F IN ("%COMMANDER_INI%") DO SET TCINI_PATH=%%~pF
Dunno if that's WINE friendly or not. But this would (should?) work WINE/Linux,

Code: Select all

basename "%COMMANDER_INI%" wincmd.ini
May need to change how the variable is referenced, maybe: $COMMANDER_INI ... ?

And this would work, with AutoHotkey,

Code: Select all

EnvGet, TCINI, COMMANDER_INI
SplitPath, TCINI,, path
path.="\"
MsgBox, path: %path%
EDIT:
And for completeness, here's a few path related functions I wrote for AHK:

Code: Select all

SplitPathCMD(fullPath, byref str1, byRef str2="", byref str3="", byRef str4="")
{
	Loop, %fullPath%, 1
		fullPath:=A_LoopFileLongPath
	if( inStr(FileExist(fullPath), "D") )
		slash:=(SubStr(fullPath, 0) <> "\" ? "\" : "")
	else
		fullPath:=(SubStr(fullPath, 0) == "\" ? SubStr(fullPath, 1,-1) : fullPath)
	Loop, 4
	{
		out:=""
		if(!sTmp:=str%A_Index%)
			break
		if(inStr(sTmp, "s") || ((full:=fullPath) && FALSE))
			Loop, %fullPath%, 1
				full:=A_LoopFileShortPath
		if((inStr(sTmp, "f") && str%A_Index%:=full) || ((full.=slash) && FALSE))
			continue
		SplitPath, full, aFile, aDir, aExt, aNameOnly, aDrive
		out:=(inStr(sTmp, "dp") ? aDir : inStr(sTmp, "d") ? aDrive : inStr(sTmp, "p") 
			? (RegExReplace(aDir, "^.:", aDir==aDrive ? "\" : "")(aFile ? "\" : "")) : "")
		out.=(inStr(sTmp, "nx") ? aFile : inStr(sTmp, "n") ? aNameOnly : (inStr(sTmp, "x") && aExt) ? "." aExt : "" ) 
		str%A_Index%:=out
	}
}

				
SplitPath( fullPath, byRef aFile="", byRef aDir="", byRef aExt="", byRef aDrive="", byRef aNameOnly="" )
{
	fullPath.=((inStr(FileExist(fullPath), "D") && SubStr(fullPath, 0) <> "\") ? "\" : "")
	SplitPath, fullPath, aFile, aDir, aExt, aNameOnly, aDrive
	aDir.=(aDir && (aDir==aDrive)) ? "\" : ""
return 
}
Example usage of SplitPathCMD() ... uses the same/similiar syntax as CMD.exe variable referencing:

Code: Select all

EnvGet, TCINI, COMMANDER_INI
SplitPathCMD(TCINI, path:="dp")
MsgBox, path: %path%
Will handle the CMD.exe letters, f d p s n x --- although f will exclude/trump the others.
E.G.
SplitPathCMD(TCINI, fullPath:="f", drive:="d", ext:="x", shortname:="snx")
MsgBox, fullpath: %fullpath%`ndrive: %drive%`next: %ext%`nshortname: %shortname%
Post Reply