Mark files based on the last characters of a certain selcted file

English support forum

Moderators: white, Hacker, petermad, Stefan2

Calafalas
Junior Member
Junior Member
Posts: 6
Joined: 2018-10-17, 15:03 UTC

Mark files based on the last characters of a certain selcted file

Post by *Calafalas »

Hi,

Is there a way to select only some files in one folder based on the last 5 characters of that file's name, using a hotkey mapped with a certain command?

Let's say I have a folder with 100 files.
They have different names, but I want to select only the 10 that have the same 5 letters/numbers+extension at the back.
So when I would use something like a "Ctrl + /", the program could check the last characters of the selected file and mark all files with those last characters.

It's a combination of the commands "cm_SelectCurrentExtension" (Select all files with same extension) and "cm_SelectCurrentNameExt".

I know I could do this by using "Ctrl + s" and then searching the extension that I need, but what I need would help me gain more time.

Thank you
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Mark files based on the last characters of a certain selcted file

Post by *petermad »

Is the 5 letters and the extension always the same?
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Calafalas
Junior Member
Junior Member
Posts: 6
Joined: 2018-10-17, 15:03 UTC

Re: Mark files based on the last characters of a certain selcted file

Post by *Calafalas »

No.
User avatar
Stefan2
Power Member
Power Member
Posts: 4133
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Mark files based on the last characters of a certain selcted file

Post by *Stefan2 »

Examples of file names are always useful if somebody ask for help.





 
Calafalas
Junior Member
Junior Member
Posts: 6
Joined: 2018-10-17, 15:03 UTC

Re: Mark files based on the last characters of a certain selcted file

Post by *Calafalas »

Let me simplify.

Let's say I have 6 files in a folder:
12345aaaaa.txt
12345bbbbb.txt
12345ccccc.txt
12345ddddd.txt
12345aaaaa.jpg
54321aaaaa.txt

When I open the folder and select the first file, with a certain command the program would mark the first and the last files in this example, because they both have the same ending (aaaaa) and they both are the same type of files (txt).

Thank you.
User avatar
Stefan2
Power Member
Power Member
Posts: 4133
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Mark files based on the last characters of a certain selcted file

Post by *Stefan2 »

So you want basically select all files with same last 9 signs as first first selected file.

Me think that need a external AutoHotkey script:
- CurrName = get current name
- Last = get last 9 signs from CurrName
- FileList = get all files in folder
- loop FileList ; if last-9-signs = Last then store name to outList
- select all files from outList

If I find some time I will try this out....



 
User avatar
tuska
Power Member
Power Member
Posts: 3740
Joined: 2007-05-21, 12:17 UTC

Re: Mark files based on the last characters of a certain selcted file

Post by *tuska »

One possibility might be to use "Everything" to filter out the desired files.

- In TC, call up the desired folder, then place the cursor on [..].
- Press Button with command: %COMMANDER_PATH%\Tools\Everything-portabel\Everything.exe -parent, parameter: %V *)
  "Everything" is called with the current path from TC
- Enter the desired text directly in "Everything", e.g. aaaaa.txt after the path and a space ... the result is displayed immediately.
- Optional: CTRL+S ... Export result list (.csv, .txt, ...)

*) Path to Everything.exe must be adjusted.
   https://www.ghisler.ch/wiki/index.php?title=Navigation - Pseudo environment variables
   %COMMANDER_PATH% ... is where TOTALCMD.EXE and TOTALCMD64.EXE is located
   (cd %COMMANDER_PATH% <enter> in TC command line ...).

In "Everything" there is the possibility to save filters, bookmarks and keyboard shortcuts.
A search history is also available.

For me, however, the question remains what should happen to the marked files afterwards.
Should they be copied or moved or should only a quick view be carried out?

In "Everything" you can also preview certain file types (menu "View" - "Preview").
and a shortcut, e.g. CTRL+Q can be defined.
Calafalas
Junior Member
Junior Member
Posts: 6
Joined: 2018-10-17, 15:03 UTC

Re: Mark files based on the last characters of a certain selcted file

Post by *Calafalas »

For me, however, the question remains what should happen to the marked files afterwards.
At this moment I am interested in quickly mark the files with the same ending so I can rename them.
User avatar
tuska
Power Member
Power Member
Posts: 3740
Joined: 2007-05-21, 12:17 UTC

Re: Mark files based on the last characters of a certain selcted file

Post by *tuska »

Calafalas wrote: 2018-10-18, 13:41 UTC
For me, however, the question remains what should happen to the marked files afterwards.
At this moment I am interested in quickly mark the files with the same ending so I can rename them.
Then you would have a real-time solution if you used "Everything" with TC.
If you are interested, you can have a look at this short summary here.

Note:
A multiple renaming as in TC does not seem to exist in "Everything".
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6450
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: Mark files based on the last characters of a certain selcted file

Post by *Horst.Epp »

tuska wrote: 2018-10-18, 14:07 UTC
Calafalas wrote: 2018-10-18, 13:41 UTC
For me, however, the question remains what should happen to the marked files afterwards.
At this moment I am interested in quickly mark the files with the same ending so I can rename them.
Then you would have a real-time solution if you used "Everything" with TC.
If you are interested, you can have a look at this short summary here.

Note:
A multiple renaming as in TC does not seem to exist in "Everything".
There is a multi-rename in Everything.
Mark some files and then use File / Rename
You get a form to specify the rules and conditions with some nice features.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3374)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69
QAP 11.6.3.2 x64
User avatar
tuska
Power Member
Power Member
Posts: 3740
Joined: 2007-05-21, 12:17 UTC

Re: Mark files based on the last characters of a certain selcted file

Post by *tuska »

Horst.Epp wrote: 2018-10-18, 16:21 UTC There is a multi-rename in Everything.
Mark some files and then use File / Rename
You get a form to specify the rules and conditions with some nice features.
Ahh, thank you! :D
I haven't noticed that yet, probably because there's no menu item of its own in "Everything",
as e.g. with menu "Edit" - "Advanced" - "Advanced Copy to Folder..." or "Advanced Move to Folder..."
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Mark files based on the last characters of a certain selcted file

Post by *petermad »

2Calafalas
Here is a solution that dosn't involve using 'Everything'

Make these 3 commands in your usercmd.ini file:

Code: Select all

[em_findfilepart]
cmd=%COMSPEC% /V /C
param=set filepart=%O && setx filepart !filepart:~-6!
iconic=1

[em_markfiles0]
cmd=SELECTFILES *%filepart%.*

[em_markfiles1]
cmd=em_findfilepart,cm_wait 500,em_markfiles0
And put this line in the [Shortcuts] section of your wincmd.ini file to use Ctrl+/ for the command

Code: Select all

[Shortcuts]
C+/=em_markfiles1

0r use this button:

Code: Select all

TOTALCMD#BAR#DATA
em_findfilepart,cm_wait 500,em_markfiles0

wcmicons.dll,39
Mark files with the same last 5 characters in the name as file under cursor


-1
To make the button:
1. Mark the green text above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctri+C).
3. Right click on TC's buttonbar and choose "Paste".
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Stefan2
Power Member
Power Member
Posts: 4133
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Mark files based on the last characters of a certain selcted file

Post by *Stefan2 »

Wonderful solution, petermad. Works perfect. Good work!


But me think he wants:
param=set filepart=%N && setx filepart !filepart:~-10!
Calafalas wrote: 2018-10-17, 17:34 UTC.... would mark the first and the last files in this example,
because they both have the same ending (aaaaa) and they both are the same type of files (txt).


Explanation
Last 5 signs of file base name %O:
param=set filepart=%O && setx filepart !filepart:~-6!

Last 5 signs of file name %N plus including dot and 3 signs extension:
param=set filepart=%N && setx filepart !filepart:~-10!
 




 
Calafalas
Junior Member
Junior Member
Posts: 6
Joined: 2018-10-17, 15:03 UTC

Re: Mark files based on the last characters of a certain selcted file

Post by *Calafalas »

@petermad

Thank you.
This is exactly what I needed. All inside, without using extra tools.

I have 2 extra questions, if you could answer:
1. what does the '500' stands for in the part 'cm_wait 500'? is it the waiting time for the selection to do it's job? can I lower it?
2. one thing that I noticed using this with some xml files:

I have this files:
aaaa01001201.xml
aaaa01001201.doc.xml
bbbb01001201.xml
bbbb01001201.doc.xml

When the selection is over a 'doc.xml' file the marking is done for the 2 'doc.xml' files, as it should.
But when the selection is on the first file "aaaa01001201.xml", the marking is aplying to all the 4 files.
Is it because it sees the 'doc.xml' as an extension?
Can I make it to mark only the first and 3rd in this example?

Thank you all again.
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Mark files based on the last characters of a certain selcted file

Post by *petermad »

2Calafalas
1. what does the '500' stands for in the part 'cm_wait 500'? is it the waiting time for the selection to do it's job? can I lower it?
It is a delay of 500 milliseconds - to give Windows enough time to set the global variable (or give TC time to recognize it). I have tried with values of 1, 10, 100m 200 and 500. sometimes 100 works, but on my system only 200 works reliably, so I have set it to 500 to also work on slower systems - you can try lower values. If the value is too low you will get the last used selection in stead of the current - so if you test lower values, you have to test on a different pattern each time, otherwise the test will alway come out correct after the second try.

2. one thing that I noticed using this with some xml files:
What you see is a limitalion of TC's SELECTFILES command. It handles *xx.* and *xx* the same way, but so does DOS's DIR command, so I cant say it is a bug.

If you always only use it on files with a 3 character extension (3 characters after the last dot), you can change it to:

Code: Select all

[em_markfiles0]
cmd=SELECTFILES *%filepart%.???
Or even better use Stefan2's solution, which will also rule out files with different extensions:

Code: Select all

[em_findfilepart]
cmd=%COMSPEC% /V /C
param=set filepart=%N && setx filepart !filepart:~-10!
iconic=1

[em_markfiles0]
cmd=SELECTFILES *%filepart%

[em_markfiles1]
cmd=em_findfilepart,cm_wait 500,em_markfiles0
menu=Mark files with the same last 9 characters in the full name of the file under cursor
But notice that both of these changes will only work with 3-character file extensions
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Post Reply