FAQs: User-Defined Command (UDC) (usercmd.ini) em_command

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

FAQs: User-Defined Command (UDC) (usercmd.ini) em_command

Post by *Stefan2 »

Create own user commands



First: what is an UDC?
wiki wrote: https://www.ghisler.ch/wiki/index.php?title=User-defined_command
User-defined commands can be used to execute external programs in an easy way.
In addition they can be used to assign a single name to an internal command which supports parameters. This is required to make them work everywhere.

These commands can be executed in various ways. User-defined commands have the em_ prefix.
This is the abbreviation for extended command and was introduced to make them easy distinguishable from internal commands.
The UDC are stored in a plain text file named usercmd.ini
Usercmd.ini is located always in the same directory as wincmd.ini (see Help menu > About TC > Paths)
If you have no usercmd.ini there, create the file first as plain text file (ASCII or UNICODE)
(if you utilize the 'Way 2' below, that file will be created for you by TC itself)

How UDC looks like:

[em_MyCommandName]
cmd=Needed. Appliaction.exe , Batch.cmd. PowerShell.ps1 or TC userdefined- or internal-command.
param=Parameter, if any, or leave empty.

[em_MyExampleBatch]
cmd="P:\ath\to my\ExampleBatch.cmd"
param="%L" "%P" "%T"


- - -

You can do with an UDC (User-defined Command, created in usercmd.ini) the same things
you can do with an button (executing an command, cd to folder, open document, run script,..),
but with UDC you have more flexibility and freedom to do more advanced things with that commands.
The advantage of an button is that he is more quicker created, with less steps and less clicks,
and an button was just the first existing possibility to execute things, and you have it in the buttonbar in front of you.

Me think the main advantage of an UDC is that you can assign an keyboard shortcut to execute that command.
The UDC "em_name" can also be used as command in an button and also just typed in the TC command line.
Apart form that, you can also use em_commands in the Start menu,the Main menu, in Alias'es and in the Directory hotlist (Ctrl+D)
- so em_commands are very versatile.

Also you have more space to create your command as you will work in notepad, in contrast to work in the small/narrow button dialog.
Maybe including features as copy&paste templates and things like spellchecker (depending on the used Notepad).


You can combine several UDCs by executing them all in one step, and also still separately each on its own:

[em_Test1] ;Execute several commands just for an test
cmd=em_Test2,em_Test3

[eM_Test2]
cmd=cm_About

[EM_Test3]
cmd=cm_HelpIndex

Now execute em_Test1, to get em_Test2 and 3 executed in the same step too. Also you can still run em_Test2 and em_Test3 alone.




You can execute UDC "em_name" (and cm_commands) by an Alias command (an shorter name to the maybe long "em_name") in TCs command line:

wincmd.ini
[Alias]
TEST=em_which_maybe_have_an_longer_Name

Type 'test' in TC command line to execute the UDC with the Name "em_which_maybe_have_an_longer_Name"

Next you can also use Alias commands placeholder %A (or %A1...%A9) in an UDC, to modify the command on the fly with parameters.




What to use as command and parameter for an UDC?

With an UDC you can trigger internal TC commands, launch system tools, execute application with selected files/folders,
run external scripts with TCs %S;%P%N or %F/%L parameters to loop over all selected files/folders.
Open web pages or documentation, filter the file list, load MultiRename or Search template, and so on.

The detailed how-to depends on your current issue; so use this keywords to search the forum for more help.

Read the help of your application in question if and how it supports to run an special action as command line command.
Next try that command yourself inside of a black cmd.exe console window (Command Prompt ; command-line interpreter). (https://en.wikipedia.org/wiki/Cmd.exe)

Once you know how that work, create a Total Commander UserDefinedCommando with that found out command.
To that UDC you can assign in next step a keyboard shortcut.
Such an UDC you can also be used as Command in an Button for the TC-Buttonbar.

TC will support you by providing Parameters to pass current Files, FileS or FolderS, Target path and more to an external script or application.
Open the help, search for "Button" to find "Dialog box: Configuration - Change button bar"
(((Or click "Operations > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar.")))
There you can find parameters to pass to the other application, like
%P > the source path to be inserted into the command line, including a backslash (\) at the end.
%N > places the filename under the cursor into the command line.
%T > inserts the current target path.
%S > insert the names of all selected files into the command line.
%L, %F and more > create a list file with the names of the selected files and directories.

Such an "%F" list you can use for application supporting such lists, like for example 7z or rar:
rar <command> -<switch> <archive> <@LISTFILES...> <path_to_extract\>
or use an own create script (MS-DOS batch;VBS;PowerShell;AutoHotkey;...) to loop over such an list file.

For script examples to process such an %F-List see below.


- - -

With more recent TC versions you can try to use ___ %P:~0,-1 ___ to remove the last sign, e.g. the trailing backslash of a path.

Or this trick: Try %P. with the dot after it. The dot means "current dir", and most programs will accept it.


Jun 10, 2021 - Total Commander 10.00 final is available now!
All placeholders in button bar or start menu like %N, %P now support substring fields
in the form :~start,end, e.g. %N:~2,5 (5 characters from the second) or %N:~-8,5 (5 from the 8-last)
To append a number directly after the length value, use another ~ character, e.g. %N:~2,5~2.

Negative values are measured from the end of the string.
Example: %P:~0,-1 cuts off the backslash from the path.


- - -
 





Create your own user commands - User-Defined Command (UDC) (em_command in usercmd.ini)



Way 1, manually by hand

To create an own user command; use this way manually by hand:

* The simplest way is to just edit the file "usercmd.ini" in your TC directory.

Note 1: Usercmd.ini is located always in the same directory as wincmd.ini (see Help menu > About TC > Paths)
Note 2: If you have no usercmd.ini there, create the file first as plain text file (ASCII or UNICODE)
(if you utilize the 'Way 2' below, that file will be created for you by TC itself)

* Create an new INI section with the wanted name for your new user defined command,
--- like for example 'em_MyCommandName' (the "em_" -part is mandatory!!! Name is non-case sensitive)

* type in your own command and parameter details (see below)
Press F1 key while in dialog for more information.

UDC entry explained:
[em_MyCommandName]
;Description, if wanted
cmd= _ _NEEDED. yourAppliaction.exe or TC- or userdefined-command.
param= _If needed, or leave empty. Needed params if any.
path= __If needed. Mostly leave it empty(default) or your wanted working dir.
menu= _USEFUL. The "tooltip=", your description, IF you want to use this em_MyCommandName as command for an button.
button= USEFUL. The "Icon file", yourAppliaction.exe or WCMICONS.DLL, IF you want to use this em_MyCommandName as command for an button.
iconic= USEFUL. The Visibility settings as you want: 1=Run minimized or -1=Run maximized or 0 or nothing=normal mode.
< If Command points to another button bar (a subbar) then Visibility settings "Run minimized" becomes "[_]Show as menu" (1)>
/END UDC entry explained

See below at "More in detail explanation" for a more in detail explanation.
Tip: right click an existent button, and then press F1 key and read more.



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


Way 2, via dialog:

To create an own user command; use this way via dialog:

This is an longer way with more clicks, but best suited for inexperienced users.

* open "Configuration > Button Bar..." (for to just add an UDC)
* click [Add] on the left (to be on the save side to not overwrite existing button by accident)
-or-
* open "Configuration > Options > Misc." (for to add UDC with an keyboard shortcut key)
* choose any key (just temporarily for creating the command, or chose one to keep)

-next-

* click on magnifying glass icon, the 'cm_commandbrowser' will be launched
(Or you can just type 'cm_commandbrowser' into the TC command line box)

-next-

* choose usercmd.ini at bottom of left listview
(the "usercmd.ini" file will be created if not existent yet, if you add a new command using new)

* on the bottom click at [New]

* enter the wanted name for your new user defined command,
--- like for example 'em_MyCommandName' (the "em_" -part is mandatory!!! Name is non-case sensitive)
* click on OK

* type in your own command and parameter details (see below),
or select a command on right side via the 'magnifying glass' symbol

Button/UDC explained:
Command = _ NEEDED. yourAppliaction.exe or TC- or userdefined-command.
Parameters = If needed, or leave empty. Needed params if any.
Start path = _If needed. Mostly leave it empty(default) or your wanted working dir.
Icon file = _ _RECOMMENDED. yourAppliaction.exe or WCMICONS.DLL.
Tooltip = _ _ _RECOMMENDED. your description.
Visibility = _ _USEFUL. Nothing=normal or minimized or maximized as you want.
/END Button/UDC explained:

* click on OK twice


See below at "More in detail explanation" for a more in detail explanation.
Press F1 key while in dialog for more information.
Additional Tip: right click an existent button, and then press F1 key and read more.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


Additional tip / explanation:

An UDC is stored in usercmd.ini in TC folder

[em_MyCommandName]
cmd= the Command
param= the Parameters
path= the Start path
menu= the tooltip
button= the Icon file
iconic= the visibility settings ("1 = minimized" // "-1 = maximized" // "0 or missed = default")
< If cmd points to another button bar (a subbar) then iconic=1 means "Show as menu" >

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Additional tip / explanation:

Interchangeable TC-Button code (TOTALCMD#BAR#DATA)

A text block starting with TOTALCMD#BAR#DATA till an ending number, is the code for an interchangeable TC-Button.
-- Copy the code > right click the TC button bar > Chose "Paste".
-- Or: right click an button in the TC button bar > Chose "Copy" > Paste to forum.

Explanation:
----------
TOTALCMD#BAR#DATA
Command
Parameters
Icon file
Tooltip if any
Start path if any
Visibility settings if any
Number of the internal command, else '-1'
----------

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -






Keyboard shortcut / Command line Alias


Add keyboard shortcut key or create an Alias to em_ or cm_ commands

To assign an keyboard shortcut key (hotkey) to an command, utilize

Configuration > Options > Misc.
>> Redefine hotkeys (Keyboard remapping)

* at "()Hotkey" choose a free key combo as keyboard shortcut (the button with the big black triangle shows the already used)
--or--
* at "()Alias" enter a few digits or letters for to use in TCs command line (for example "help" for to execute cm_HelpIndex)
*
* For "Command:" click on the magnifying glass
* and choose the wanted command by double clicking on it.
(To filter type em_ or cm_ and maybe more letters or just an keyword like 'copy')
* Apply with the green check mark button!!!
* Close the options dialog with [OK]
* Click on OK


Please note that there are programs which reserve hotkeys system-wide without asking the user!
So if your hotkey is suddently not working (anymore) maybe some other application is stealing that key?



You can also manipulate the wincmd.ini's "[Shortcuts]" section manually by hand.

Examples:
C=Ctrl/Strg
A=Alt
S=Shift/Umschalt
CA=Ctrl+Alt
CS=Ctrl+Shift
CAS=Ctrl+Alt+Shift
Fx=F-functionskey
Add an Letter or Digit to complete the shortcut.

[Shortcuts]
;Enable 'F2'-key to start inline-rename mode, additional to origin 'Shift+F6'
F2=cm_RenameOnly
;Enable 'Ctrl+F' to start find-files, additional to origin 'Alt+F7'
C+F=cm_SearchFor
;Use 'Ctrl+O' to launch DOS-Box in current path
C+o=cm_ExecuteDOS
;Disable 'Alt+F4' (Exit, close program), load Help instead
A+F4=cm_Keyboard
;Ctrl+Shift+Alt+F5 erstelle Archive im selben Panel
CA+F5=cm_PackFiles
;Ctrl+Shift+Alt+F5 erstelle Archive im selben Panel und lösche Source
CAS+F5=cm_PackFiles
C+P=cm_CopyNamesToClip
CS+P=cm_CopyFullNamesToClip
AS+F4=em_ShellNewFileTemplates

[ShortcutsWin]
; Same as [shortcuts], but together with Windows key
CAS+P=em_CopyPathBaseNamesToClip ; press Win+Ctrl+Alt+Shift++P

[Alias]
abo=cm_About ;TEST only
ed=em_NewFile_YYYYMMDD
otcf=em_OpenTCFolder
sel=cm_SpreadSelection ;([Shift+]Num +) ;Select group
selsh=cm_ShrinkSelection ;([Shift+]Num -) ;Unselect group
selun=cm_ClearAll    ;=524;Unselect all
si=em_NirCmdClipboardSaveimage
ps=em_LaunchPowerShell
hh=cm_HelpIndex




Explanation for ALIAS by Claude Charries (Clo):

Since the 7.02 version, TC allows to define “Aliases” with several parameters.

For example : an alias to start another instance of TC with other directories in the panes.
(Note: this is just an example how to use Aliasparameter for Alias, not necessarily an useful command)

Create an User defined “em_xyz” command :
usercmd.ini (or see above for the way via the GUI):
[em_myTC2]
button=C:\Totalcmd\wcmicons.dll
cmd=c:\Totalcmd\TOTALCMD.EXE
param=/L=%A1 /R=%A2
path=c:\Totalcmd
menu=Second instance of TC

Create the alias :
* "Configuration > Options > Misc. >>> Redefine hotkeys (Keyboard remapping)".
* Alias: TC2
* Command : em_myTC2
Click the button with the nick to confirm, then click Apply and OK

Use the alias :
On the command-line, type for instance :
TC2 "O:" "D:\My Documents"

Then, a second instance of TC will start
with the root of the O: drive in the left side panel,
and the folder D:\My Documents in the right side panel.

Or type just TC2 if you doesn't have need to use the parameters.

Feel free to add other parameters :
In the em_TC param=/L=%A1 /R=%A2 /i=%A3
On the command-line type for example : TC2 "O:" "D:\My Documents" "MyCustomTC.ini"
that will start the second instance with another configuration file in addition.



- - -


Example usage of an Alias >>> https://ghisler.ch/board/viewtopic.php?p=407035#p407035









More in detail explanation:


QUOTATION
Take care on the right quotation! Always set paths in quotes.
Some TC parameter needs quotes too, other set quotes on its own. Best set "%T" "%L" "%F" in quotes yourself.
Parameter %S %P, %N and %P%S or %P%N must NOT be quoted, as they set quotes itself, if spaces are dedected.
So some files or paths get quoted, others not. Use own script to handle that quoting yourself, or use tricks like "%P%O.%E" instead of %P%N.
Note: That parameter, which returns paths, have automatically an trailing backslash added (so an trailing quote may be interpreted as being escaped).
Check the help of your application in question to read how it supports command line arguments.
Different Interpreters (Applications/Coding languages) have different quoting rules and often remove the surrounding quotes,
so double (""%P%N"") or even triple the douple quote quotings ("""%P%N""") or use single quotes if advisable ('%P%N').

Or use an own script to handle quotes yourself. I usually use a VBScript to loop over each line of the temp file from the "%L" parameter.


Quotation Examples:

Code: Select all

Command: cmd /k
Parameters: ""%%PROGRAMFILES%%\Tools\SysInternals Suite\sigcheck.exe" %P%N"
That is: " " % %PROGRAMFILES% % \Tools\SysInternals Suite\sigcheck.exe " %P%N "


Another for me working example:
Command: cmd /k ""%PROGRAMfiles%""\Tools\SysInternals Suite\sigcheck.exe"
Parameters: %P%N
That is: cmd /k " " %PROGRAMfiles% " " \Tools\SysInternals Suite\sigcheck.exe "


Example try of doubled double percent signs:
Command=cmd /c
Parameters=Start "" "%%Commander_Path%%\Tools\Notepad2.exe" %P%N
(Please note that TC will quote %P%N himself, so don't quote them by yourself)
(Please note that MS-DOS START command expect first "..." to hold wanted windows title, an empty title in our example)

Button/UDC explained:
Press F1 key while in dialog for more information.

--- Command =
< NEEDED. Your script or application with full or relative path. Take care, always set paths in quotes.! >
< Environment variables like %ProgramFiles% are supported, use %Commander_Path% for the TC-folder. (https://www.ghisler.ch/wiki/index.php/Navigation)>
< Or use a TC internal CM_commands or an user defined EM_commands "UDC" (see "Magnifying glass" symbol) >
< This field also accepts command line paramters (but NOT TC params with only one %, like %N) as long as you properly quote them. >
< Command: '-1' insert an separator // Command: '-2' insert a line break in button bar to get two rows. >

< To process many selected files at once we often call an own script (MS-DOS Batch/VBScript/JS/PowerShell/AutoHotkey/...) or use one of this tools:
MakeBAT by Christian Ghisler - https://www.ghisler.com/dplugins.htm
TCBL aka Bat Builder Launcher - http://tccfestuff.free.fr
List2multiInstance aka List To MultiInstance aka L2M by Andrey V. Sorokin - https://www.ghisler.com/dtools.htm
List2Run by JackFoo (call app for each selected file again and again) - http://ghisler.ch/board/viewtopic.php?t=3418
lst2str by JackFoo (call app one time only with all files as arguments) - https://www.ghisler.com/dtools.htm
lst2clip aka List2Clipboard (addition to cm_CopyFullNamesToClip) - http://www.ghisler.ch/board/viewtopic.php?t=1853
>

--- Parameters =
< If needed, or leave empty. Maybe parameters for your application, if need. Take care on the right quotation! >
< Or TCs parameter like %P, %N, %F, case sensitive! (press F1 key for help). Take care on the right quotation! >
%P > the source path, including a backslash (\) at the end.
%N > the filename.
%T > the current target path.
%S > insert the names of all selected files into the command line.
%L, %F and more > create a list file with the names of the selected files and directories.

< A leading question-mark '?' will pop-up the command for inspectation and manipulation before actual executing >

< If you need environment variables in both command AND parameters box, then write them both together in the command box:
INSTEAD of
Command: "%COMMANDER_PATH%\TOOLs\AHK\AutoHotkey.exe"
Parameters: "%COMMANDER_PATH%\TOOLs\AHK\my script.ahk"
USE
Command: "%COMMANDER_PATH%\TOOLs\AHK\AutoHotkey.exe" "%COMMANDER_PATH%\TOOLs\AHK\my script.ahk"
Parameters:
>
< You may try to put %EnvironmentVariables% into the Parameters box,
but you have to double the % signs like in a DOS-Batch file (%%envvar%%),
but TC will NOT expand that %%var%% there, they will be passed with
single % signs (%var%) and it's the duty of the called application to resolve them. >


--- Start path =
< If needed. Mostly leave it empty (recommended), as TC use current path as "Start path" anyway. >

--- Icon file =
< RECOMMENDED. Use WCMICONS.DLL or "path to your application exe or to your icon resurce" >
< For more Icon resources / libraries visit: https://ghisler.ch/board/viewtopic.php?f=3&t=43593&p=305387#p305387 >

--- Tooltip =
<RECOMMENDED. An hint for you, so you know what this button will do. Use pipe-symbol '|' to insert line breaks.>

--- Visibility settings =
< USEFUL. Chose "[_]Run minimized (1)" or "[_]Run maximized (-1)" or "Nothing = normal mode (0)" >
< If Command points to another button bar (a subbar) then Visibility settings "Run minimized" becomes "[_]Show as menu" (1)>


* click on OK twice

/END Button/UDC explained
Press F1 key while in dialog for more information.



Pitfalls:
- Some expanded TC parameter get automatically quoted, some not. Depends on if path contains space, and on parameter-combination sometimes.
- That parameter, which returns paths, have automatically an trailing backslash added.
-
-








Script examples to process such an %F or %L -List (here w/o your special issue, that need to be coded individually)

TC provide a list of all selected files or folders you can f.ex. process by your own script (or by applications like 7z and rar which supports listfiles)
If you are not familiar in writing scripts (MS-DOS batch; VisualBasicScript; AutoHotkey; and so on) search the forum or ask in the forum for some help.

To execute such an script, call them from an button or an UserDefinedCommand while providing TCs' %S, %P%N or %F or %L parameter to the script.

Commando : "D:\rive\path to\folder\your script.cmd" ((script examples see below))
--or better be portable, use an subfolder of your TC folder:
Commando : "%Commander_Path%\YourScriptsSubFolder\your script.cmd"
Parameters: "%L" -or- "%F" , quoted in case your username contains spaces.
Start path: empty
Icon : wcmicons.dll
Tooltip : describe what this script will do for you



Powershell -Example

Code: Select all

 Cmd=Powershell 
 Param="%L"
# // The script
# // Check arguments:
If ($Args.Count -eq 0) { "Please use '%L' as TCs parameter. Also select one or more files first. Script quits here."; return}
# //DEBUG:
# Notepad $Args[0]
# //Do the WORK:
 TYPE $Args[0] | ForEach{ ...}
VBS-Example

Code: Select all

Set FSO = CreateObject("Scripting.FileSystemObject")
SET WSO = CreateObject("WScript.Shell")
sTCtempList = Wscript.arguments.Item(0) ' The TC temp file due the "%L"
  If  FSO.FileExists(sTCtempList) Then
      ' WSO.run "notepad " & sTCtempList
      Set oTextStream = FSO.OpenTextFile(sTCtempList,FORREADING)
      Do Until oTextStream.AtEndOfStream
      ...
      Loop
      oTextStream.Close
   Else
      WScript.Echo "Input file  sTCtempList  not found."
   End If
AHK-Example

Code: Select all

vTCtempfile=%1%
Loop, Read, %vTCtempfile%
{
    vCurrTempFileLine = %A_LoopReadLine%
    MsgBox Curr line is:`n%vCurrTempFileLine%
}

MS-DOS Batch Example

Code: Select all

@echo off
setlocal enabledelayedexpansion
rem Button Command: cmd /k
rem Button Parameters: "%F" "%P" "%T"
set tc_lst=%1
set tc_src=%2
set tc_dst=%3

if -%3==- echo First parameter must be filelist path, second and third - source and target path. && pause && goto :EOF

for /F "usebackq delims=" %%I in (%tc_lst%) do (
   rem ============== Insert your custom commands here ==============
   echo Exp:       %%~I
   echo Full Path:   %%~fI
   echo LW:      %%~dI
   echo Path:      %%~pI
   echo File Name:   %%~nI
   echo Extension:   %%~xI
   echo ShortPath:   %%~sI
   echo Attrb:      %%~aI
   echo Date Time:   %%~tI
   echo Size:      %%~zI
   echo ----------------------------
   rem ==============================================================
)
pause
cls
endlocal


Example script (DOS MS Batch) for to execute from such UDC:


TC provides a list of all selected files ("%L" or "%WL" or others).
We execute a batch which takes that list as argument "%1" and processes each line of that temp list.


The basic is just:
@echo off
for /f "delims=" %%Z in ('type %1') do( ECHO Do something with "%%Z" )
pause



A full script could be (needs adjustment for your use case!!!):

ForEachSelectedDO_ExampleBatch.cmd

Code: Select all

@echo off
REM Found at https://ghisler.ch/board/viewtopic.php?p=365186#p365186
REM Stefan 2019-12-18 v001
GOTO START

#########################################################################
## TotalCommander Button:
https://ghisler.ch/board/viewtopic.php?p=344803#p344803
Commando  : "%Commander_Path%\ForEachSelectedDO_ExampleBatch.cmd"
Parameters: "%L" "%P" "%T"
Start path:
Icon      : C:\WINDOWS\System32\imageres.dll --or-- wcmicons.dll
Tooltip   : ForEachSelectedDO_ExampleBatch

## User-Defined Command (UDC) (usercmd.ini) em_command:
https://ghisler.ch/board/viewtopic.php?f=3&t=52425
[em_MyCommandName]
cmd="%Commander_Path%\ForEachSelectedDO_ExampleBatch.cmd"
param="%L" "%P" "%T"

## Add shortcut key to em_ or cm_ commands
Utilize "Configuration > Options > Misc." to assign the hot key.
* open "Configuration > Options > Misc."
* by "shortcuts" choose a free key combo
* click on the magnifying glass
* type em_ (or cm_) and choose the wanted command by double clicking on it
* close the options dialog with [OK]
* click on OK
#########################################################################

:START
REM Unicode file names: chcp 65001 ; Windows cp: CHCP 1250 
ECHO ---------------------------- INFOs
ECHO TCs Param list: L or WL
ECHO L: %1
ECHO TCs Source folder: P
ECHO P: %~2
ECHO TCs Target folder: T
ECHO T: %~3
ECHO ---------------------------- Do IT
for /f "delims=" %%Z in ('type %1') do (
	 echo Do something with 
	 echo %%Z
	 echo Name=%%~nxZ
	 echo BASE=%%~nZ
	 echo EXTE=%%~xZ
	 echo COPY form %2
	 echo TO %3
	 echo * * * * * * * * * * * * next file / line
 )
ECHO ---------------------------- All done.
PAUSE






Examples of working usercmd.ini entries:

totalcmd\usercmd.ini wrote:[em_hide_selected]
cmd=cd
param=*.*|%S
menu=Hide Selected Files
button=wcmicons.dll,73

[em_mydocuments]
cmd=cd %$PERSONAL%
menu=My Documents (personal)

[em_calc]
cmd=calc.exe


[em_newdir]
cmd=%COMSPEC% /c
param=if not exist "%T%O" md "%T%O"
menu=Make directory with same name as file under cursor in opposite panel
button=%COMMANDER_PATH%\wcmicons.dll,29


[em_ExtractToFolder]
; extracting a zip into folder with ZIP-filename as folder name.
; https://ghisler.ch/board/viewtopic.php?p=384429#p384429
; Usage: 7za <command> [<switches>...] <archive_name>
; x: eXtract files with full paths
; -y: assume Yes on all queries
; -o{Directory}: set Output directory
; TC params:
; %O filename without extension (use for foldername)
; %N filename
; %P for path is not needed as TC works with current active directory as path anyway
cmd="%Commander_Path%\TOOLs\PACKER\7za.exe"
param=x -y -o"%O" %N
; ; Note: %O needs to be quoted if archive name contains white space,
; ; %N must not, as TC do this itself. Use an leading '?' as parameter to explore that by yourself.
; ; (Use "%O.%E" instead of %N to avoid that automatism if that disturps you in any way)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



More collected information from the forum:

petermad wrote:
petermad, Power Member
Posted: Sat Mar 22, 2014 1:29 Post subject: Meaning and use of "iconic" in Default.bar
Source URL: http://ghisler.ch/board/viewtopic.php?t=39951

iconic=1 is what you get when you check the option "Run minimized" in the "Change button bar" dialog.
iconic=-1 is what you get when you check the option "Run maximized".

If the button you are editing points to another button bar (a subbar) then iconic=1 means "Show as menu".

If iconic= is not present or just says iconic= then it means iconic=0.



Whether iconic=0 is present or not depends on how you started editing the button:

1. If you use the menu: "Configuration" -> "Button bar" and then find and edit the button in the "Change button bar" dialog then iconic=0 is set.
Same thing if you right click on the blank space in the end of the button bar and choose "Change".

2. If you on the other hand right click on an button in the bar and choose "Change" then the dialog "Change single button" opens,
and if you press OK in this dialog with "Run minimized" unchecked, then no iconic=0 is set and an existing iconic=0 for that button is removed.


Also if you copy and paste a button to the bar, then the items in the .bar file are mixed up and not written in sequence.
If you open the "Change button bar" dialog and press OK, then the items in the .bar file will be sorted correctly again and missing iconic=0 are added.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


Alternative usercmd.ini
petermad wrote:AFAIK it is not possible to redirect usercmd.ini (to another place than the folder of the wincmd.ini)

But if you use a menu file (not TC's internal English menu),
then you can also store user commands in a file with a name that corresponds the name of the menu file.

If for example your menu file is wcmd_arb.mnu then you can store user commands in a file named wcmd_arb.ini

If your menu file is wcmd_mytranslation_eng.mnu then you can store user commands in a file named wcmd_mytranslation_eng.ini etc.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


Extended English Menus for Total Commander by petermad

Hint:
Extended English Menus for Total Commander (by petermad), is a alternative TC menu which contains almost every TC command (and some more)
Download it at: http://www.totalcmd.net/authors/1223914.html

You can see user-defined commands heavily exploited in peters' Extended Menus, with up to 546 em_commands (Windows 10 version).
In his menus the user commands are stored in wcmd_*.ini files that correspond the wcmd_*.mnu file - keeping the usercmd.ini file untouched.
Examples of peters' work
[em_ext_cmdelevated]
cmd=*%COMSPEC% /C
param=Start /D"%P"
menu=Command Prompt as Administrator
button=cmd.exe

[em_ext_copynamestofile1]
cmd=%COMSPEC% /C
param=copy "%WF" "%PSELECTEDFILES.txt"
menu=Copy selected filenames to file in current folder
iconic=1

[em_ext_savetabs]
cmd=SAVETABS
param=?%Ptotalcmd.tab
menu=Save tabs from active side to file

[em_ext_openlanguage]
cmd=OPENLANGUAGEFILE
menu=Open English Language/Menu (build-in)

[em_ext_openmenu]
cmd=OPENLANGUAGEFILE .MNU
menu=Open English Menu (build-in)

[em_ext_openas]
cmd=RunDll32.exe SHELL32.DLL,OpenAs_RunDLL
param=%p%n
menu=Open with (Windows)

[em_ext_loadbar]
cmd=OPENBAR
param=%P%O.bar
menu=Open button bar under cursor
button=wcmicons.dll,14

[em_ext_list_imagine]
cmd=%COMMANDER_EXE% /S=L:Pimagine
param=%Z%P%N
menu=Show with Imagine
button=%COMMANDER_PATH%\PLUGINS\WLX\imagine\Imagine64.exe

[em_ext_list_irfanview]
cmd=%COMMANDER_EXE% /S=L:P
param=%Z%P%N
menu=Show with IrfanView / XnView / GDI+

[em_ext_newdir]
cmd=%COMSPEC% /c
param=if not exist "%T%O" md "%T%O"
menu=Make directory with same name as file under cursor in opposite panel
button=%COMMANDER_PATH%\wcmicons.dll,29

[em_ext_comp]
cmd=%COMMANDER_EXE% /S=C
param=%Z %C1 %C2
menu=Compare Contents (separate instance)
button=%COMMANDER_EXE%,23

[em_ext_sync]
cmd=%COMMANDER_EXE% /S=S
param=%Z%X "%P" "%T"
menu=Syncronize Directories (separate instance)
button=wcmicons.dll,48

[em_ext_find]
cmd=%COMMANDER_EXE% /S=F
param=%Z %P
menu=Find Files (separate instance)
button=%COMMANDER_EXE%,0

[em_ext_opentabs]
cmd=OPENTABS
param=%P%O.tab
menu=Load folder tabs from file under cursor, replace tabs

[em_ext_show_all]
cmd=cd *.*
menu=Show All Files
button=wcmicons.dll,13

[em_ext_show_images1]
cmd=cd *.8bps *.acr *.adi *.ani *.anm *.b3d *.bmp *.cam *.cdr *.cdt *.cel and so on and so on
menu=Show Image Files (1 - g)
button=wcmicons.dll,24

[em_ext_show_images_web]
cmd=cd *.gif *.jpg *.jpeg *.jpe *.png *.bmp
menu=Show Image Files (web formats)
button=wcmicons.dll,24

[em_ext_commanderpath]
cmd=cd %COMMANDER_PATH%
menu=Current Total Commander Folder

[em_ext_commanderdrive]
cmd=cd %COMMANDER_DRIVE%\
menu=Current Total Commander Drive

[em_ext_commanderini]
cmd=%COMMANDER_EXE% /S=L:AT1 "%COMMANDER_INI%"
menu=Current Total Commander ini File

[em_ext_commandercfg]
cmd=cd %COMMANDER_INI%
menu=Current Total Commander Configuration Folder

[em_ext_commanderdata]
cmd=cd %APPDATA%\Ghisler
menu=Current Total Commander Data Folder

[em_ext_commanderlocaldata]
cmd=cd %$LOCAL_APPDATA%\Ghisler
menu=Current Total Commander local Data Folder

[em_ext_editwincmd]
cmd=%COMMANDER_INI%
path=%COMMANDER_INI%\..
menu=Edit main ini-file

[em_ext_editwcx_ftp]
cmd=wcx_ftp.ini
path=%COMMANDER_INI%\..
menu=Edit wcx_ftp.ini

[em_ext_editusercmd]
cmd=usercmd.ini
path=%COMMANDER_INI%\..
menu=Edit usercmd.ini


[em_ext_documents]
cmd=cd ::{450D8FBA-AD25-11D0-98A8-0800361B1103}
menu=My Documents (virtual)

[em_ext_programfilesx86]
cmd=cd %PROGRAMFILES(X86)%
menu=Program Files (32bit)

[em_ext_mydocuments]
cmd=cd %$PERSONAL%
menu=My Documents (personal)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


Icons for your own em_commands in the main menu:
https://ghisler.ch/board/viewtopic.php?f=3&t=67366
by *petermad » Mon Mar 30, 2020 13:49
If you want icons for your own em_commands in the main menu, you have to edit myicons.inc accordingly.
The number of the first em_command in your .mnu file will be 10000 in the myicons.inc file,
so if you want to use for example icon 88 in myicons.dll for your first em_command, you have to put:
10000=88
in your myicons.inc file.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -






- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -




My copy&paste template

todo

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

For your issue use this for example:
Command =
Parameters =
Start path = leave empty
Icon file = WCMICONS.DLL
Tooltip = your description
Visibility = as you want
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FAQs: How to create an button / Icons / Variables / Quoting
https://ghisler.ch/board/viewtopic.php?p=344803#p344803
FAQs: Button-code: How-to Copy Share Paste a button ('TOTALCMD#BAR#DATA')
https://ghisler.ch/board/viewtopic.php?p=335879#p335879
FAQs: Button - How to execute more than one command at once
https://ghisler.ch/board/viewtopic.php?p=287794#p287794
FAQs: User-Defined Command (UDC) (usercmd.ini) em_command
- Create own commands to use in button or to execute them by an keyboard shortcut.
https://ghisler.ch/board/viewtopic.php?p=344777#p344777
FAQs: TCs' internal commands - how-to find and use them
https://ghisler.ch/board/viewtopic.php?p=289931#p289931


. .
. .



Post Reply