-- Inspired from this thread.
TC_SelectSequence.ahk (version 2.50)
Download:
▪ [Download Directory]
▪ Compiled TC_SelectSequence.exe (with source files) [RAR]
Usage (primary):
Command-Line Parameters:Move cursor to a file in a TC panel (Click, Arrows, etc).
Press, Hotkey-combination, or Button.
Files matching the 'numerical sequence' of file will be selected.
TC_SelectSequence automates the tedious part of creating a regex for a group of similiar files.
When you have the files you want selected, you could:OR:
- Invert Selection
- Save Selection (to file) (so you can resume the selection later)
- Show only Selected files.
The first 3 steps, could be done with TCMC.exe or a very small AHK script, and assigned to an EM_ command or button -- possible as an expansion of this script with a few more line-commands, besides the sole one of /edit, currently.
- Show only Selected files.
/edit - Functionality is identical to normal Auto-Select, except the script will open up the "Define selection" dialog so you can make further/additional changes to the 'regex' string.
/anynum :: Allows the sequence match to be \d+ instead of \d{#}.
Normally, if you Auto-Select on "File1.txt", only File0.txt thru to File9.txt would get selected. With the /anynum parameter, File1.txt, File33.txt, File999.txt, etc would be matched and selected.
/braces :: Will document this, when I post v2.55 (later today) - as I believe the functionality will change (for better defaults). Or possibly split it into 2 parameters -- but I think more logical defaults will allow it to remain at one optional parameter only.
It primarily deals with what should happen when a number is at the end of a fileName in braces or brackets, e.g. File10(1).txt, File10 (1).txt, File1 (100).txt
Usage examples:
All of the following files would get selected, if the cursor is just on one of the files (and press button or hotkey):Or files that are more in line with Digital Cameras:A Set 4 of Files Cateogry 7 001.txt
A Set 4 of Files Cateogry 7 001.txt
A Set 4 of Files Cateogry 7 004.txt
A Set 4 of Files Cateogry 7 006.txtExplanation:GEDCX8001.jpg
GEDCX8002.jpg
GEDCX8003.jpg
GEDCX8004.jpg
GEDCX8005.jpgThe code creates a Filter called, TC_SelectSequence
And a regex to match the files, in the cases above:It also will match if there are non-number characters following the last number sequence: Eg: GEDCX8004__.jpg
- Regex: "^A Set 4 of Files Category 7 \d{3}\.txt$"
- Regex: "^GEDCX\d{4}\.jpg$"
Setup:
Create a User-Defined command(s):em_TCSelectSequence
Command: "C:\Location\of\TC_SelectSequence.exe"Create a TC Hotkey (e.g): Shift+Win+sem_TCSelectSequenceEdit
Command: "C:\Location\of\TC_SelectSequence.exe" /editCreate a TC Hotkey (e.g): Ctrl+Shift+Win+s
- Assign to em_TCSelectSequence
Additionally, one could add either the FullCommand or the User-Command to a Button, or StartMenu, etc.
- Assign to em_TCSelectSequenceEdit
UnMerged Script (required #includes are in the Download)
Code: Select all
;;
;; TC_SelectSequence.ahk
;; v2.50
;; Balderstrom, Nov.2010
;;
#SingleInstance, Force
#NoEnv
SetBatchLInes, -1
SendMode Input
nArgs=%0%
ReadArgs(nArgs)
return
ReadArgs(nArgs=0)
{
Loop, % nArgs
{
editFindStr:=(editFindStr || %A_Index%=="/edit")
matchAnyNum:=(matchAnyNum || %A_Index%=="/anynum")
locateBrace:=(locateBrace || %A_Index%=="/braces")
}
IniRead, iniSearch, %A_ScriptDir%\TC_SelectSequence.ini, Config, searches, %A_Space%
TC_SelectSequence(iniSearch, editFindStr, matchAnyNum, locateBrace)
return
}
ExitNow(key="")
{
Send, % key ? key : ""
ExitApp
}
TC_SelectSequenceAutoSave()
{
WinWaitActive, ahk_class TSTDTREEDLG
ControlSetText, TAltEdit1, TC_SelectSequence, A
Send, {Enter}
WinWaitActive, ahk_class #32770,,1
if( !ErrorLevel )
Send, {Enter}
WinWaitActive, ahk_class TCOMBOINPUT
ExitNow("{Enter}")
}
TC_SelectSequence(iniSearch="searches", editFindStr="", matchAnyNum="", locateBrace="")
{
aPanel:=QueryActivePanelID( cID1, cID2)
aText:=LB_QueryText(aPanel, cPos:=LB_FindCursorPos( cID1 ))
ControlGetText, aPath, TMyPanel3, A
RegExMatch(aPath aText, "(.*)\>(.*\\)?([^\\]+)(\.[a-zA-Z]+) \>?", aFile)
fileName:=aFile3
fileExt :=aFile4
;partPath:=aFile1 "\" aFile2
;fullPath:=aFile1 "\" aFile2 aFile3 aFile4
RegExMatch(fileName, "(.*[^ ])[ ]?(([\(\{\[])(\d+)([\)\}\]]))$", sTmp)
;MsgBox, sTmp1: %sTmp1%_`nsTmp3: %sTmp3%`nsTmp4: %sTmp4%`nsTmp5: %sTmp5%
if( sTmp2 )
{
RegExMatch(sTmp1, "(.*\D)?(\d+)(\D+)?$", split)
;MsgBox, split1: %split1%`nsplit2: %split2%`nsplit3: %split3%
if( (s4:=strlen(sTmp4)) > (s2:=strlen(split2)) )
{
;; Number in brackets is longer than the prev#
;; We will use the (001) as the sequenceNumber.
filter:=RegExReplace(sTmp1, "([\^\$\.\+\{\(\[\]\)\}])", "\$1")
filter.="[ ]?\" sTmp3 (matchAnyNum ? "\d+\" : "\d{" s4 "}\") sTmp5 "\" fileExt
filter:="^" filter "$"
}
else
{
;; Number in brackets, at the end of filename is shorter than the prev#
;; So if we have enabled /braces, we are only going to match files w/ that
;; else we will basically ignore the (1) --> ([ ]\(1\))? "optional".
split1:=RegExReplace(split1, "([\^\$\.\+\{\(\[\]\)\}])", "\$1")
split2:=(matchAnyNum ? "\d+" : "\d{" s2 "}")
split3:=RegExReplace(split3, "([\^\$\.\+\{\(\[\]\)\}])", "\$1")
filter:="^" split1 split2 split3 "([ ]?\" sTmp3 "\d+\" sTmp5 ")"
filter.=(locateBrace ? "\" : "?\") fileExt "$"
}
}
else
{
RegExMatch(fileName, "(.*\D)?(\d+)(\D+)?$", split)
split1:=RegExReplace(split1, "([\^\$\.\+\{\(\[\]\)\}])", "\$1")
split2:=(matchAnyNum ? "\d+" : "\d{" strlen(split2) "}")
split3:=RegExReplace(split3, "([\^\$\.\+\{\(\[\]\)\}])", "\$1")
filter:="^" split1 split2 split3
filter.=(locateBrace ? "([ ]?[\{\[\(]\d+[\)\]\}])?" : "" ) "\" fileExt "$"
}
;MsgBox, Final`nfilter: %filter%
TC_iniWrite( filter,iniSearch, "TC_SelectSequence_SearchFor" )
TC_iniWrite( "", iniSearch, "TC_SelectSequence_SearchIn" )
TC_iniWrite( "", iniSearch, "TC_SelectSequence_SearchText" )
TC_iniWrite( "0|000002001020|||||||||0000| ", iniSearch, "TC_SelectSequence_SearchFlags" )
PostMessage, 0x433, 521,,, A ; cm_SpreadSelection | Select group
WinWaitActive, ahk_class TCOMBOINPUT
ControlSetText, Edit1, >TC_SelectSequence, A
if( !editFindStr )
ExitNow("{Enter}")
Send, {Tab}{Tab}{Enter} ;Send, !{d}
WinWaitActive, ahk_class TFindFile
aWinDefine:=WinExist("A")
while( (aWin:=WinActive("A")) == aWinDefine )
{
Sleep, 250
}
WinGetClass, aClass, ahk_id %aWin%
if( aClass=="TCOMBOINPUT" )
ExitNow("{Esc}")
TC_SelectSequenceAutoSave()
return
}
#include %A_ScriptDir%\Lib\TC.ahk
#include %A_ScriptDir%\Lib\LB.ahk
/braces, works in 2.50
Future ideas, a few more command-line parameters:
/invert (selection)
/showselected (only)
/unselect
and
/hide - which would do /invert, /showselect, /unselect
Version History:
2.50
▪ Improved: /braces command-line parameter.
That /braces parameter is (beta), it's defaults will likely change.
2.45
▪ Added: TC_SelectSequence.ini :: if you run a localized (non-english) version of TC.
† Not sure if this is neccessary.
2.40
▪ Removed hotkeys.
▪ Removed English language specifics: should work with any language localization of Total commander.
▪ Provided compiled download, .exe in a .rar
2.35
▪ Added, /braces and /anynum args (line-command parameters)
▪ Rewrote regex handler, should properly find files that have ^$(){}[] in their name (now).
2.21
▪ Added, Enter/NumpadEnter triggers to "Define selection" dialog (to notify script it should Save & Exit.)
2.2
▪ Implemented "/edit" line-command.
▪ Removed commented out/unused Hotkey section.
2.0
▪ Writes to wincmd.ini directly.
▪ Minor regex fix for files that are all numbers. ie 0001.jpg