/* desc - basic file renamer. filter (listed) files by length. Apply several predefined actions Auth - Target Updated - Mar09 Credits - Skwire (for adding the 'resize on move' functionality via Titan's anchor script) - Lanux128 (for the original request) - Cranioscopical (for feature requests, feedback, and encouragement) * capture single click (X2) edits */ ;fileinstall, MTF.ico,MTF.ico,0 #singleinstance process, exist MyPID:= errorlevel cfold:=0 cfile:=0 isfold:=0 File_Fold:=0 Recurse:=1 Folds:=1 midstr:=0 Sess_List:= ListIndex:=0 ifnotexist MTF.Ini gosub, options else { iniread, FiltLen, MTF.ini, Filter, Length /* loop,10 { iniread, TmpLst, mtf.ini,MRU, MRU%A_index% if tmplst myMRU.= tmpLst . "`n" } tmplst:= */ } menu, tray, add, Options menu, tray, add, About menu, tray, add menu, tray, add, Quit ;menu,tray,icon,MTF.ico ;menu,tray, nostandard Menu, mymenubar, add, Options ;Menu, mymenubar, add, MRU Menu, mymenubar, add, Quit ;Menu, mymenubar, add ;, " " ;Menu, mymenubar, add, About ;gui, menu, mymenubar Gui, +Resize gui, add, button, y6 x10 GSearch default, Add Files gui, add, checkbox, y4 x70 vRecurse gSetme checked1, Recursive gui, add, checkbox, y19 x70 Check3 vFile_Fold gfoldme checked0, ALL gui, add, edit, y7 x155 w45 vCharLen gSetMe gui, add, updown, vTargLen range1-256,%filtLen% gui, add, text, y9 x205, Filter on Length gui, add, button, y6 x285 gRefreshME, Refresh gui, add, listview, r16 x10 w500 grid nosort nosorthdr -readonly altsubmit vListMe gSetMe,File|Chars|MyPath gui, add, button, x345 y6 w40 gSelectAll, All gui, add, button, x390 y6 w 40 gSelectNone, None gui, add, button, x454 y6 gClearList, Clear List gui, add, Text, y42 x530 vtxt1, Starting Pos guicontrol,hide, txt1 gui, add, checkbox, y42 x525 vPreDef1 gsetme checked0, Trim left gui, add, edit, y36 x600 w45 vLTrim gSetMe gui, add, updown, range1-256 vLTrim_upd,1 gui, add, text, y90 x550 vtxt2, # Chars guicontrol, hide, txt2 gui, add, checkbox, y90 x525 vPreDef2 gsetme checked0, Trim Right gui, add, edit, y85 x600 w45 vRTrim gSetMe gui, add, updown, range1-256 vRTrim_upd,1 gui, add, checkbox, y65 x555 vMidStr gsetme checked0, Mid gui, add, groupbox, y115 x520 w180 h140 vmyGroupBox gui, add, Checkbox, y127 x525 vPreDef3 gsetme checked0, Custom Replace gui, add, edit, y145 x525 w170 vFindMe gSetMe Gui, add, text, y170 x525 vFindMe_txt, enter search characters or strings `nin comma separated format gui, add, edit, y200 x525 w170 vRepMe gSetMe Gui, add, text, y220 x525 vRepMe_txt, enter replacement character or `nstring (one only) gui, add, button, y6 x525 w170 gPreDef vApply_btn, Apply gui, add, button, y260 x525 w170 gUndoMe vUndo_btn, Undo gui, add, statusbar LV_modifyCol(1,440) LV_modifyCol(2,"40 Integer") sb_setparts(100,100) sb_settext("folders:",1) sb_settext("files:",2) sb_settext("selected:",3) gui, show, w700 center , Maim That File! return ;############################################################################################# ;############################################################################################# GuiSize: { Anchor( "ListMe" , "wh", 0 ) Anchor( "Apply_btn" , "x" , 0 ) Anchor( "Undo_btn" , "x" , 0 ) Anchor( "PreDef1" , "x" , 0 ) Anchor( "LTrim" , "x" , 1 ) Anchor( "LTrim_upd" , "x" , 1 ) Anchor( "TXT1" , "x" , 1 ) Anchor( "TXT2" , "x" , 0 ) Anchor( "MidStr" , "x" , 1 ) Anchor( "PreDef2" , "x" , 0 ) Anchor( "RTrim" , "x" , 1 ) Anchor( "RTrim_upd" , "x" , 1 ) Anchor( "myGroupBox", "x" , 1 ) Anchor( "PreDef3" , "x" , 1 ) Anchor( "FindMe" , "x" , 1 ) Anchor( "FindMe_txt", "x" , 1 ) Anchor( "RepMe" , "x" , 1 ) Anchor( "RepMe_txt" , "x" , 1 ) } Return ;############################################################################################# ;############################################################################################# #ifwinactive,Maim That File! ~#F10::reload Quit: ~#F12:: guiclose: exitapp return ~^A:: SelectAll: LV_modify(0,"Select") return SelectNone: LV_modify(0,"-Select") return ClearList: LV_Delete() cfold:= 0 cfile:= 0 sb_settext("folders:",1) sb_settext("files:",2) Guicontrol,,FoldOnly,0 Gui, submit, nohide EX_List.= Sess_List Sess_list:= Listindex:=0 MyFold:= return RefreshME: LV_Delete() cfold:= 0 cfile:= 0 Loop, parse, Sess_List, `n { myfold:= a_loopfield gosub, rerun } Return SetMe: gui, submit, nohide if midstr = 1 { guicontrol,,predef1,0 guicontrol,,predef2,0 guicontrol,hide,predef1 guicontrol,hide,predef2 guicontrol,show,txt1 guicontrol,show,txt2 } else if midstr = 0 { guicontrol,hide,txt1 guicontrol,hide,txt2 guicontrol,show,predef1 guicontrol,show,predef2 } if Recurse = 0 { folds:=0 file_Fold:= 1 guicontrol,,file_fold, Files only } Gui, submit, nohide if a_guievent = doubleclick gosub EditMe if a_guicontrol = ListMe sb_settext("Selected: " . LV_GetCount("selected"),3) return FoldMe: gui, submit, nohide if File_Fold = 0 { folds:=1 recurse:=1 guicontrol,,recurse,1 guicontrol,,file_fold, ALL } else if file_Fold = 1 { folds:=0 ; recurse:=0 ; guicontrol,,recurse,0 guicontrol,,file_fold, Files only } else if file_Fold = -1 { folds:=2 recurse:=1 guicontrol,,recurse,1 guicontrol,,file_fold, Folders only } gui, submit, nohide return guidropfiles: Myfold:= a_guievent gosub, Session_List gosub, rerun return ~^C:: ifwinnotactive ahk_pid %MyPID% { clipboard = send ^{C} return } if LV_Getcount("Selected") > 1 { msgbox, Too many items selected. `nSelect a single item and try again return } LV_GetText(copied,LV_getnext(),1) clipboard = clipboard = %copied% copied:= return Options: gui, +owndialogs ifexist, MTF.ini iniread, FiltLen, MTF.ini, Filter, Length inputbox, FiltLen, Default Filter Length, Default filter length,,135,110,,,,,%FiltLen% if errorlevel return iniwrite, %filtlen%, mtf.ini, filter, length guicontrol,,CharLen, %filtLen% gui, submit, nohide return About: return MRU: /* */ return Session_List: ifnotinstring, sess_list, %myFold% { Sess_List.= myfold . "`n" listindex++ } MRUno:=1 tmpindex:= listindex - 9 loop, parse, sess_list, `n { if not a_loopfield Break if listindex < 11 iniwrite, %a_loopfield%, MTF.ini, MRU, MRU%a_index% else if A_index > %tmpindex% { msgbox, %sess_list% `n index - %a_index% `n field - %a_loopfield% `nMRU no - %MRUNo% iniwrite, %a_loopfield%, MTF.ini, MRU, MRU%MRUno% MRUno++ } } ; sess_list:=tmplst ; tmplst:= MRUno:=1 ; listindex:=10 ;} ;menu, MRU, deleteall ;loop, parse, Sess_List, `n ; menu, add, a_loopfield return ;############################################################################################# ; ADD FILES + FOLDERS ;############################################################################################# #ifwinactive, Maim That File! ~^O:: Search: fileselectfolder,MyFold,::{20d04fe0-3aea-1069-a2d8-08002b30309d},2 If errorlevel return if myfold = ::{20d04fe0-3aea-1069-a2d8-08002b30309d} return if myfold = return gosub, Session_List rerun: if myfold = ::{20d04fe0-3aea-1069-a2d8-08002b30309d} return if myfold = return loop, %myfold%\*.*, %folds%, %recurse% { stringgetpos,TmpVar,a_loopfilename,`.,R if errorlevel = 1 { tmpvar:=strlen(a_loopfilename) isFold:=1 } if tmpvar >= %CharLen% { LV_Add("",a_loopfilename,tmpvar,A_loopfiledir) if isfold = 1 cfold++ else cfile++ } IsFold:=0 } LV_modifyCol(3,"SortDesc") LV_modifycol(1,440) LV_modifycol(2,40) lv_modify(1,"selected:") sb_settext("folders: " . cfold ,1) sb_settext("files: " . cfile ,2) return ;############################################################################################# ;EDITING ;############################################################################################# #ifwinactive, Maim That File! ~F2:: ifwinnotactive ahk_pid %MyPID% { send {F2} return } EditMe: gui, +owndialogs MyRow:=LV_GetNext(0) LV_GetText(MyPath,myrow,3) LV_GetText(OldFile,MyRow,1) LV_GetText(OldLen,MyRow,2) TmpXtn:=substr(oldfile,oldlen+1) inputbox, newfile, Edit Value, %MyPath%,,,115,,,,,%oldfile% if errorlevel return stringgetpos,NewLen,newfile,`.,R LV_modify(MyRow, col1 ,newfile,newlen) gosub, fmove filegetattrib, isDir, %MyPath%\%oldfile% if isdir = D gosub, rerun Return ;############################################################################################# PreDef: gui, +owndialogs if (predef1 = 0) and (predef2 = 0) and (predef3 = 0) and (betweens = 0) return msgbox,4,,You are about to make permanent changes to the selected files. `nDo you want to continue? (there's no going back) ifmsgbox, no return myrow:=0 loop % LV_getcount("selected") { MyRow:=LV_GetNext(myrow) LV_GetText(MyPath,myrow,3) LV_GetText(OldFile,MyRow,1) LV_GetText(OldLen,MyRow,2) TmpXtn:=substr(oldfile,oldlen+1) newFile:= OldFile if (midstr = 1) and (OldLen > ltrim + rtrim) { stringtrimleft,tmpfile,newfile, (ltrim + rtrim) - 1 stringLeft,newfile, newfile, LTrim - 1 newfile.= tmpfile } stringgetpos, NewLen, newfile,`.,R if errorlevel NewLen:=strlen(Newfile) if (predef1 = 1) and (LTrim < OldLen) stringtrimLeft,newfile, newfile,%LTrim% stringgetpos, NewLen, newfile,`.,R if errorlevel NewLen:=strlen(Newfile) if (predef2 = 1) and (RTrim < NewLen) { stringleft,newfile,newfile,(NewLen - RTrim) newfile.= tmpxtn } stringgetpos,NewLen,newfile,`.,R if errorlevel NewLen:=strlen(newfile) if predef3 = 1 { stringleft, newfil_, newfile,NewLen loop, parse, FindMe, csv stringreplace,newfil_,newfil_,%A_loopfield%,%RepMe%,all if strlen(newfil_) > 0 newfile:= newfil_ . tmpxtn } stringgetpos,NewLen,Newfile,`.,R if errorlevel NewLen:=strlen(newfile) gosub, fmove } guicontrol,,predef1,0 guicontrol,,predef2,0 guicontrol,,predef3,0 gui, submit, nohide gosub, rerun return FMove: if oldfile = %newfile% return filegetattrib, isDir, %MyPath%\%oldfile% ifexist, %MyPath%\%newfile% { msgbox, 8196,,%newfile% exists`, overwrite? { ifmsgbox yes { myUndo.= mypath . "`," . oldfile . "`," . newfile . "`n" if isdir = D filemovedir, %MyPath%\%oldfile%, %MyPath%\%newfile%,r else filemove, %MyPath%\%oldfile%, %MyPath%\%newfile%,1 LV_modify(MyRow, col1 ,newfile,newlen) } } } else { myUndo.= mypath . "`," . oldfile . "`," . newfile . "`n" if isdir = D filemovedir, %MyPath%\%oldfile%, %MyPath%\%newfile%,r else filemove, %MyPath%\%oldfile%, %MyPath%\%newfile%,1 LV_modify(MyRow, col1 ,newfile,newlen) } return ;############################################################################################# ;UNDO ;############################################################################################# #ifwinactive, Maim That File! ^z:: UndoMe: gui, hide gui, 2:default gui, 2:add, listview, r15 grid nosort nosorthdr -wantf2 readonly vUNList, Seq|Path|Old Name|New Name loop, parse, myundo ,`n { stringsplit, unArr, a_loopfield, `, LV_Add("", a_index, unarr1 , unarr2 , unarr3) } lv_modifycol() LV_modifyCol(1,"Integer") lv_modifycol(1,"sortDesc") gui, 2:add, button, w50 gSelectAll, All gui, 2:add, button, y243 x70 w50 gSelectNone, None gui, 2:add, button, y243 x130 w50 gUnDone, Undo gui, 2:add, button, y243 x190 w50 gGoBack, Go Back gui, 2:show, w500 center return GoBack: 2guiescape: 2guiclose: gui, 2:destroy gui, 1:default gosub, rerun gui, show return UnDone: Loop % LV_GetCount("Selected") { LV_GetText(UnPath,LV_GetNext(),2) LV_GetText(UnOld,LV_GetNext(),3) LV_GetText(UnNew,LV_GetNext(),4) filegetattrib,UnAttr,%unpath%\%unnew% if unattr = D filemovedir,%unpath%\%unnew%,%unpath%\%unold%,r else filemove,%unpath%\%unnew%,%unpath%\%unold%,1 LV_Delete(LV_GetNext()) stringreplace,MyUndo, MyUndo, %unpath%`,%unold%`,%unnew%`n } Return ; ------------------------------------------------------------------------ ; Anchor ----------------------------------------------------------------- ; http://www.autohotkey.com/forum/topic4348.html ------------------------- ; ------------------------------------------------------------------------ Anchor(c, a = "", r = false) { ; v3.6 - Titan ;OutputDebug, c: %c% static d GuiControlGet, p, Pos, %c% If ex := ErrorLevel { Gui, %A_Gui%:+LastFound ControlGetPos, px, py, pw, ph, %c% } If !(A_Gui or px) and a Return i = x.w.y.h./.7.%A_GuiWidth%.%A_GuiHeight%.`n%A_Gui%:%c%= StringSplit, i, i, . d := a ? d . ((n := !InStr(d, i9)) ? i9 : "") : RegExReplace(d, "\n\d+:" . c . "=[\-\.\d\/]+") Loop, 4 x := A_Index, j := i%x%, i6 += x = 3 , k := !RegExMatch(a, j . "([\d.]+)", v) + (v1 ? v1 : 0) , e := p%j% - i%i6% * k, d .= n ? e . i5 : "" , RegExMatch(d, "\Q" . i9 . "\E(?:([\d.\-]+)/){" . x . "}", v) , l .= p%j% := InStr(a, j) ? (ex ? "" : j) . v1 + i%i6% * k : "" If r rx = Draw If ex ControlMove, %c%, px, py, pw, ph Else GuiControl, Move%rx%, %c%, %l% }