%|envvar| question

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

%|envvar| question

Post by *sirksel »

If you are doing a custom command where the command is cmd /c but the param needs to use a looping structure over say %L, like: for /f %%k in %L do (___)... is there a way to use the new %|envvar| syntax to make the %%k work inside param=? Currently, I have to use external batch files, but I was thinking for some of the shorter ones, I now might be able to make them one-liners fully inside total commander.
User avatar
nsp
Power Member
Power Member
Posts: 1913
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: %|envvar| question

Post by *nsp »

You should try %%%%k instead of %%k...
User avatar
petermad
Power Member
Power Member
Posts: 16030
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: %|envvar| question

Post by *petermad »

Usually %%k works for variables and %%envar%% for environment variables in the Parametesr field if the command is cmd /c

For example does this work fine for me:

Code: Select all

em_ext_copyonetomulti]
cmd=%COMSPEC% /C
param=if not exist "%P" (echo Error) else if exist %Y%P%S1\* (echo Error) else if exist %P%N\* (echo Error) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" xcopy %P%N "%%n" /H /R /K /Y
menu=Copy the content of file under cursor to marked files in same panel
button=wcmicons.dll,62
iconic=1
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Fla$her
Power Member
Power Member
Posts: 2997
Joined: 2020-01-18, 04:03 UTC

Re: %|envvar| question

Post by *Fla$her »

2sirksel
cmd may only need pseudo-variable TC when using the %|var| syntax, otherwise the classic doubling of the percent sign can still be used in the parameter field. However, I tested the functionality implemented according to my proposal with %|var| with %ComSpec% and didn't encounter problems interacting with other variables. Give a problematic example, let's deal with it.
Overquoting is evil! 👎
sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

Re: %|envvar| question

Post by *sirksel »

Thanks so much for all the help. All this time, I was under the mistaken impression that %%k didn't work before in the parameter field. I was just going through the latest changes in TC11 and trying to improve functionality in my menus where I could. But I think I understand now. What was impossible before was %var% in param, and now we can use %|var| to do that, correct? But it sounds like %%f always worked. And in param, I need to do %%k or %%%%k? It seems like you all are saying I need to double the double percent sign. Correct?
User avatar
petermad
Power Member
Power Member
Posts: 16030
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: %|envvar| question

Post by *petermad »

2sirksel

If you in a batch file would use %%k you will have to use %%k in TC's Parameters field
If you in a batch file would use %var% you will have to use %%var%% in TC's Parameters field

Notice that %k in a DOS command line is the same as %%k in a batch file, and that TC's Parameter field resembles the DOS command line, NOT a line in a batch file.

So In TC's Parameters field you use %%k - not %%%%k.

If you want to "translate" a batch file with several lines into a TC Parameter field, you need to replace the line shifts in the batch files with & (or &&) and you may have to add some parenthesis to distinguish the different batch file lines, when they are put on one line.
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

Re: %|envvar| question

Post by *sirksel »

You all are so helpful! Thanks so much. I think I've got it all straight in my head now. Just one last question... so what does the %|var| change enable that you couldn't do before? Is it just alternate syntax for %%var%% in params, or is there more to it? Just need to get this last piece straight in my head before I go modifying all my menus. :) Many thanks.
User avatar
petermad
Power Member
Power Member
Posts: 16030
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: %|envvar| question

Post by *petermad »

In order to use %%envar%% the program in the command line (for example cmd.exe) has to be able to resolve %var%.
%|var| is resolved by TC an can therefore be used by any program.

Examples
This will work:

Code: Select all

[em_notepad1]
cmd=notepad.exe "%commander_path%\history.txt"

This will not work

Code: Select all

[em_notepad2]
cmd=notepad.exe "%|commander_path|\history.txt"

This will work:

Code: Select all

[em_notepad3]
cmd=notepad.exe
param="%|commander_path|\history.txt"

This will not work

Code: Select all

[em_notepad4]
cmd=notepad.exe
param="%commander_path%\history.txt"

This will not work

Code: Select all

[em_notepad5]
cmd=notepad.exe
param="%%commander_path%%\history.txt"

This will work

Code: Select all

[em_notepad6]
cmd=cmd.exe /c
param=notepad.exe "%%commander_path%%\history.txt"

This will work

Code: Select all

[em_notepad7]
cmd=cmd.exe /c
param=start ""  notepad.exe "%|commander_path|\history.txt"

This will work

Code: Select all

[em_notepad8]
cmd=cmd.exe /c
param=start "" notepad.exe "%%commander_path%%\history.txt"

This will not work

Code: Select all

[em_notepad9]
cmd=cmd.exe /c
param=start "" notepad.exe "%commander_path%\history.txt"



1. You can only use %|envvar| in the Parameters field
2. You can only use %envvar% in the Command field
3. You can use %%envvar%% in the Parameters field IF the command is cmd.exe (or equivalent)
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

Re: %|envvar| question

Post by *sirksel »

Thanks for the examples. It's now super clear to me how this works, and where I can use it to make things better in my menus. I was definitely missing a few of these conceptual points until you connected them for me with your helpful examples. Many thanks.
User avatar
petermad
Power Member
Power Member
Posts: 16030
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: %|envvar| question

Post by *petermad »

2sirksel

Just another example - since Total Commander itself resolves environment variables in the command line, this button will work:

Code: Select all

TOTALCMD#BAR#DATA
%COMMANDER_EXE%
L=%%COMMANDER_PATH%%\history.txt R=%|COMMANDER_PATH|\totalcmd.inc
%COMMANDER_EXE%
or this:

Code: Select all

TOTALCMD#BAR#DATA
%COMMANDER_EXE% %COMMANDER_PATH%\history.txt
%|COMMANDER_PATH|\totalcmd.inc
%COMMANDER_EXE%
To make the buttons:
1. Mark the text in the boxes here above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctrl+C).
3. Right click on TC's buttonbar and choose "Paste".
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
white
Power Member
Power Member
Posts: 5788
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: %|envvar| question

Post by *white »

petermad wrote: 2023-09-06, 09:49 UTC ..since Total Commander itself resolves environment variables in the command line, this button will work:
Except when the Total Commander program folder contains one or more spaces.
User avatar
petermad
Power Member
Power Member
Posts: 16030
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: %|envvar| question

Post by *petermad »

white wrote: 2023-09-06, 10:17 UTC Except when the Total Commander program folder contains one or more spaces.
Yes, then we need double quotes:

Code: Select all

TOTALCMD#BAR#DATA
%COMMANDER_EXE%
L="%%COMMANDER_PATH%%\history.txt" R="%|COMMANDER_PATH|\totalcmd.inc"
%COMMANDER_EXE%

Code: Select all

TOTALCMD#BAR#DATA
%COMMANDER_EXE% "%COMMANDER_PATH%\history.txt"
"%|COMMANDER_PATH|\totalcmd.inc"
%COMMANDER_EXE%
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Post Reply