Copy file names and paths to variables

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
wetware05
Junior Member
Junior Member
Posts: 64
Joined: 2023-05-15, 16:10 UTC

Copy file names and paths to variables

Post by *wetware05 »

Hi.

(I don't know if such an option exists. If it already exists let me know)

To improve certain features of Total Commander or to customize them, it is very useful to resort to automation programs such as Lua or AutoHotkeys. It would be very convenient for this purpose if the commands of the cm_CopyNamesToClip or cm_CopyFullNamesToClip type had a replica where the name of the file or the full path was copied to a variable. Such pariables could be customized in the .ini file and the command would be something like cm_CopyNamesToVal or cm_CopyFullNamesToVal.

This would be more convenient because it would not clutter the clipboard with unnecessary information when working with Lua scripts or AutoHotkeys. In the post https://www.ghisler.ch/board/viewtopic.php?t=79028 there is an example of interaction between AutoHotkey and TCM, it would have been easier for me (and it would be more optimal) to modify such a script if TCM had those commands and could be "called" from AutoHotkeys.
User avatar
beb
Senior Member
Senior Member
Posts: 436
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Copy file names and paths to variables

Post by *beb »

There're some of those, e.g., %N, %P, %P%N, %S, %L, %WL, %UL

Here's my relatively recent post (where you can assess in person how they can work):
Hint: Passing TC variables %N,%P,%P%N,etc, as input to PowerShell.ps1 and turning them now into the PS script variables:
viewtopic.php?t=78801

Edit:

From Total Commander 11.00 beta2 help [Help - Index tab > User defined menu > Parameters:]:

Code: Select all

Parameters: Here you can specify command line parameters.
Note: All parameters now support substring fields in the form :~start,length, e.g. %N:~2,5 or %N:~-8,5 . To append a number directly after the length value, use another ~ character, e.g. %N:~2,5~2. Negative vaules are measured from the end of the string. Example: %P:~0,-1 cuts off the backslash from the path.
The Start value -0 is special: %N:~-0,20 copies the first 20 characters of the name without extension, %N:~-0,-20 the first 20 characters of the extension without the name.
Special parameters:
? as the first parameter causes a Dialog box to be displayed before starting the program, containing the following parameters. You can change the parameters before starting the program. You can even prevent the program's execution.
%P                  causes 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. Especially useful for packers.
%M                  places the current filename in the target directory into the command line.
%O                  places the current filename without extension into the command line. 
%E                  places the current extension (without leading period) into the command line.
%B, %B0..%B9        adds a directory name from the path (including the relative path from branch view, or the search result).
                  %B or %B0 = parent directory, %B1 = grandparent directory etc.
%BT, %BT0..%BT9     adds a directory name from the target path (without the relative path from branch view).
                  %BT or %BT0 = parent directory, %BT1 = grandparent directory etc.
%B-, %B-0..%B-9     adds a directory name from the path without the relative path from branch view, empty in search result).
                  %B- or %B-0 = parent directory, %B-1 = grandparent directory etc.
%B+, %B+0..%B+9     adds a directory name from the path (with branch view), counting from the start with the drive/server name:
                  %B+ drive letter with ":", %B+0 = drive letter without ":", %B+1 = first directory or share, %B+2 = second directory etc.
%S                  insert the names of all selected files into the command line. Names containing spaces will be surrounded by double quotes. Please note the maximum command line length of 32767 characters.
%S10                insert the names of the first 10 selected files (max.) into the command line. Allows you to limit the number of file names passed to the program. You can use any other number.
%P%S                insert the names of all selected files into the command line, with full path. Names containing spaces will be surrounded by double quotes. Do NOT put quotes around %P%S yourself!
%R                  like %S, but with selected names from the target panel
                  Notes: %N and %M insert the long name, while %n and %m insert the DOS alias name (8.3). %P and %T insert the long path name, and %p and %t the short path name. (Same for %o, %e, %b and %s). %p/%t inserts the ftp URL of the directory for ftp connections.
                  By putting %P, %p, %T or %t directly in front of %S or %s, the path name is inserted with the file name for each file. Example: %P%S inserts the long path and file name for all selected files.
%C1                 Like the first parameter of "Compare by content": First selected file, or file under cursor
%C2                 Like the second parameter of "Compare by content": Second selected file, or first selected in target panel, or file with same name in target panel. Note: If the right panel is active and less than 2 files are selected, %C1 and %C2 will be reversed.
%C3..%C9            Selected files Nr. 3 .. 9 in source panel, empty if not enough selected
%c1..%c9            Like %C1..%C9, but with 8.3 names and paths
%%                  inserts the percent-sign.
%L, %l, %F, %f, %D, %d, %WL, %WF, %UL, %UF create a list file in the TEMP directory with the names of the selected files and directories, and appends the name of the list file to the command line. The list is deleted automatically when the called program quits. Only one list per command is supported. Include parameter %a to also append selected files and directories from the target panel. 10 types of list files can be created:
%L                  Long file names including the complete path, e.g. c:\Program Files\Long name.exe
%l                  (lowercase L) Short file names including the complete path, e.g. C:\PROGRA~1\LONGNA~1.EXE
%F                  Long file names without path, e.g. Long name.exe
%f                  Short file names without path, e.g. LONGNA~1.EXE
%D                  Short file names including the complete path, but using the DOS character set for accents.
%d                  Short file names without path, but using the DOS character set for accents.
%Q                  Turn off automatic quotation marks around certain parameters like %P%N when the name contains a space. The user will then have to place them by himself.
%UL, %UF            like %L and %F, but with a UTF-8 Unicode list file (with byte order mark)
%WL, %WF            like %L and %F, but with a UTF-16 Unicode list file (with byte order mark)
%v                  Insert virtual file name in case of file system plugins like "virtual panel", where %N pastes the name of the real file (in the file system) to which the entry points to
%V                  Like %v, but including the full path (including the plugin name)
%X                  Interprets the following parameters after this parameter as left/right instead of source/target:
                  %P, %p (left path), %T, %t (right path), %N, %n (left name), %M, %m (right name),
                  %S, %s (left selected), %R, %r (right selected)
                  Example: %X%P %T  sends left and right path to e.g. an external sync tool
%x                  Interprets the following parameters after this parameter again as source/target
                  Example: %X%P %x%P sends left and source path to the called program
%Y                  anywhere in the parameters: Pass empty list to program when nothing is selected when using one of the List parameters like %L, or multi-file parameters like %S. Otherwise, the file under the cursor would be passed.
%y                  anywhere in the parameters: When nothing is selected when using one of the List parameters like %L, pass all other parameters except for the list parameter to the called program.
                  Note: %Y%y works like %y when something is selected or the cursor stands on "..", otherwise it selects the file under the cursor.
%Z                  anywhere in the parameters: Allow to pass archives as path to programs for %P or %T when inside an archive
                  Example: %Z%P passes name of archive to external tool when TC shows contents of an archive
%|envvar|           Insert environment variable envvar in the parameters field. Using %envvar% directly isn't possible, because the % sign is already used for placeholders. Therefore this modified syntax needs to be used. The "command" field still uses the normal %envvar% field.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
wetware05
Junior Member
Junior Member
Posts: 64
Joined: 2023-05-15, 16:10 UTC

Re: Copy file names and paths to variables

Post by *wetware05 »

Hi, beb, thanks for the information.

Resorting to PowerShell doesn't seem like a good idea to me.

The idea of ​​copying the filename or path to a variable came to me because a few weeks ago I came across the script below. Through Autohotkey, total commander is requested a postmessage, where the number 2017 or 2018 requests the file name (cm_CopyNamesToClip) or the name with the full path (cm_CopyFullNamesToClip). I don't know where such numbers come from, somewhere there has to be a table of equivalences.

The problem is that these commands send the information to the clipboard, and it is not the most suitable for some cases, where the file name is constantly requested, because the "garbage" clipboard is saturated. The ideal would be to send the information to a variable.

Code: Select all

^F8::
ClipBoard:=""
;PostMessage, 0x433, 2017, 0,, ​​A ; Equivalent to cm_CopyNamesToClip
PostMessage, 0x433, 2018, 0, A ; Equivalent to cm_CopyFullNamesToClip
ClipWait
MsgBox, %Clipboard
User avatar
beb
Senior Member
Senior Member
Posts: 436
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Copy file names and paths to variables

Post by *beb »

wetware05 wrote: 2023-05-16, 19:53 UTC Resorting to PowerShell doesn't seem like a good idea to me.
Fla$her wrote: 2023-04-28, 10:13 UTC You can use VBScript, JScript, AutoIt, AHK, gentee, LangMF, Kixtart, etc...
As you can see, AHK is listed there.

All those %P%N, %P%S, %L, %WL, %WF, %UL, %UF could be the "Equivalent to cm_CopyFullNamesToClip" depending on the specifics of the task.
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
hi5
Power Member
Power Member
Posts: 553
Joined: 2012-11-03, 11:35 UTC
Contact:

Re: Copy file names and paths to variables

Post by *hi5 »

You can use AutoHotkey AND avoid the clipboard by using listbox code by Crash&Burn @ https://www.autohotkey.com/board/topic/7471-list-of-filenames-selected-in-panel-of-total-commander/?p=368810

I use it in QuickView descript.ion viewer (QVD) @ https://github.com/hi5/qvd
F4MiniMenu (Forum) - Open selected file(s) from TC in defined editor(s) - A (minimalistic) clone of F4Menu
Source at GitHub (AutoHotkey). TCSyncComments (copy file comments)
wetware05
Junior Member
Junior Member
Posts: 64
Joined: 2023-05-15, 16:10 UTC

Re: Copy file names and paths to variables

Post by *wetware05 »

Thanks for the suggestions hi5 and beb.

I already had the issue resolved. The request I have made is to make things easier, as libraries are used, when if TCM had a way to copy the name and path to a variable it would be better for programmers or script writers.

Below the script to know the name under the mouse, even if the element is not selected:

Code: Select all

#Include lib\UIA_Interface.ahk
uia := UIA_Interface()

F8::
if WinActive( "ahk_exe TOTALCMD64.exe" ){
ControlGetText sPath, Window7
sPath:=StrReplace(sPath,">","\")
Element := uia.ElementFromPoint()
itemName := Element.GetCurrentPropertyValue(30005)
if (itemName == "")
itemName := "Not 'Name'"
RegExMatch(itemName, "^[^\t]*", RegName)
FullPath:= sPath RegName
}

MsgBox, %FullPath
Call a library that you have to download from here: https://github.com/jethrow/UIA_Interface

(It has the defect that it looks for the name of a control —the path that appears next to the command line—, and it changes depending on how TCM is configured, this would not happen if TCM returned the path and the name of the control in a variable. file, as requested. I have to parse what beb suggests and its table. I would have to see if autohotkey can request the information from those parameters.)
Post Reply