/* desc - basic file renamer. filter (listed) files by length. Apply several predefined actions Auth - Target Updated - March/April 09 Credits - Lanux128 (for the original request) - Skwire (for adding the 'resize on move' functionality via Titan's anchor script) - Cranioscopical (for feature requests, feedback, and encouragement) */ 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 Myfold:= "::{20d04fe0-3aea-1069-a2d8-08002b30309d}" menu, File_, add menu, File_, deleteall ifnotexist MTF.Ini { fileappend,[filter]`nlength=1`n[MRU]`nMRU1=%a_space%`nMRU2=%a_space%`nMRU3=%a_space%`nMRU4=%a_space%`nMRU5=%a_space%`nMRU6=%a_space%`nMRU7=%a_space%`nMRU8=%a_space%`nMRU9=%a_space%`nMRU10=%a_space%`n,MTF.ini menu, MyMRU, add menu, MyMRU, deleteall } else { loop,10 { iniread, MRU, mtf.ini,MRU, MRU%A_index% if MRU = ERROR { menu, MyMRU, add menu, MyMRU, deleteall Break } else if MRU= { menu, MyMRU, add menu, MyMRU, deleteall Break } else if MRU = %a_Space% { menu, MyMRU, add menu, MyMRU, deleteall Break } else { Mru_%a_index%:= MRU menu, MyMRU, add, %MRU%, mru1 } } } iniread, FiltLen, MTF.ini, Filter, Length menu, tray, add, Options menu, tray, add, About menu, tray, add menu, tray, add, Quit menu,tray,icon,MTF.ico menu,tray, nostandard Menu, FileMenu, add, Options Menu, FileMenu, add, Quit Menu, FileMenu, add Menu, FileMenu, add, MRU, :MyMRU Menu, FileMenu, add Menu, FileMenu, add, About Menu, mymenubar, add, &File, :FileMenu gui, menu, mymenubar Gui, +Resize gui, add, button, y6 x10 GSearch default, ADD ;dd Files ;------------------------------------------------------------------------------------ ;Old ver ;------------------------------------------------------------------------------------ /* gui, add, checkbox, y4 x50 vRecurse gSetme checked1, Recurse gui, add, checkbox, y19 x50 Check3 vFile_Fold gfoldme checked0, ALL gui, add, edit, y7 x120 w45 vCharLen gSetMe gui, add, updown, vTargLen range1-256,%filtLen% gui, add, text, y9 x170, Name Length gui, add, button, y6 x245 gRefreshME, Refresh gui, add, dropdownlist,y7 x460 w241 vCurr_Sess gSetMe gui, add, listview, r16 x10 w500 grid nosort nosorthdr -readonly altsubmit vListMe gSetMe,File|Chars|MyPath gui, add, button, x305 y6 w40 gSelectAll, All gui, add, button, x350 y6 w 40 gSelectNone, None gui, add, button, x400 y6 gClearList, Clear List */ ;------------------------------------------------------------------------------------ ;New ver ;------------------------------------------------------------------------------------ gui, add, radio, y4 x50 vFile_Fold group gFoldMe, Files gui, add, radio, y4 x95 gFoldMe, Folders gui, add, radio, y19 x50 checked1 gFoldMe, All gui, add, checkbox, y19 x95 vRecurse gSetme checked1, Recurse gui, add, edit, y7 x160 w45 vCharLen gSetMe gui, add, updown, vTargLen range1-256,%filtLen% gui, add, text, y9 x208, # Chars ;Name Length gui, add, button, y6 x250 gRefreshME, Refresh gui, add, dropdownlist,y7 x440 w260 vCurr_Sess gSetMe gui, add, listview, r15 x10 w500 grid nosort nosorthdr -readonly altsubmit vListMe gSetMe,File|Chars|MyPath gui, add, button, x305 y6 w40 gSelectAll, All gui, add, button, x348 y6 w40 gSelectNone, None gui, add, button, x395 y6 w40 gClearList, Clear ;------------------------------------------------------------------------------------ gui, add, Text, y72 x525 vtxt1, Starting Pos guicontrol,hide, txt1 gui, add, checkbox, y72 x515 vPreDef1 gsetme checked0, Trim left gui, add, edit, y70 x585 w45 vLTrim gSetMe gui, add, updown, range1-256 vLTrim_upd,1 gui, add, text, y97 x545 vtxt2, # Chars guicontrol, hide, txt2 gui, add, checkbox, y97 x515 vPreDef2 gsetme checked0, Trim Right gui, add, edit, y95 x585 w45 vRTrim gSetMe gui, add, updown, range1-256 vRTrim_upd,1 gui, add, checkbox, y120 x515 vMidStr gsetme checked0, Mid gui, add, groupbox, y133 x515 w185 h120 vmyGroupBox gui, add, Checkbox, y120 x585 vPreDef3 gsetme checked0, Custom Replace gui, add, edit, y145 x522 w170 vFindMe gSetMe Gui, add, text, y170 x525 vFindMe_txt, enter search characters or strings `nin comma separated format gui, add, edit, y200 x522 w170 vRepMe gSetMe Gui, add, text, y220 x525 vRepMe_txt, enter replacement character or `nstring (one only) gui, add, button, y37 x520 w170 gPreDef vApply_btn, Apply gui, add, button, y260 x520 w170 gUndoMe vUndo_btn, Undo gui, add, statusbar LV_modifyCol(1,440) LV_modifyCol(2,"40 Integer") sb_setparts(100,100,380) sb_settext("folders:",1) sb_settext("files:",2) sb_settext("selected:",3) sb_settext("Ver:0.00.00.00.14",4) gui, show, w700 x100 y100, 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 ) Anchor( "Curr_Sess" , "wh" , 1 ) Anchor( "UnList" , "wh", 0 ) Anchor( "Nun" , "x" , 1 ) Anchor( "Act" , "x" , 1 ) Anchor( "rtn" , "x" , 1 ) } Return ;############################################################################################# ;############################################################################################# #ifwinactive,Maim That File! ;###### ~#F10::reload ;###### Quit: ~#F12:: guiclose: exitapp return ;###### ~^A:: SelectAll: LV_modify(0,"Select") return ;###### ~^U:: SelectNone: LV_modify(0,"-Select") return ;###### CTRL+ZERO ~^0:: ClearList: LV_Delete() cfold:= 0 cfile:= 0 sb_settext("folders:",1) sb_settext("files:",2) Guicontrol,,FoldOnly,0 Guicontrol,,Curr_Sess,| Gui, submit, nohide ;EX_List.= Sess_List Sess_list:= Listindex:=0 MyFold:= return ;###### ~^R:: RefreshME: LV_Delete() cfold:= 0 cfile:= 0 Loop, parse, Sess_List, | { 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, 1 } 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 = 1 ;files folds:=0 else if file_Fold = 2 ;folders { folds:=2 recurse:=1 guicontrol,,recurse,1 } else if file_Fold = 3 ;all { folds:=1 recurse:=2 guicontrol,,recurse,1 } gui, submit, nohide return ;###### guidropfiles: loop, parse, a_guievent, `n { myfold:= a_loopfield gosub, Session_List } gosub, refreshme gosub, MRU_Menu 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 filtlen = 1 ifexist, MTF.ini iniread, FiltLen, MTF.ini, Filter, Length inputbox, FiltLen, Default Filter Length, Default filter length,,135,115,,,,,%FiltLen% if errorlevel return iniwrite, %filtlen%, mtf.ini, filter, length loop, 10 { iniread, MRU,mtf.ini, MRU,MRU%A_index% if MRU = ERROR iniwrite, %a_space%, mtf.ini, MRU, MRU%a_index% } guicontrol,,CharLen, %filtLen% gui, submit, nohide return ;###### About: gui, +owndialogs msgbox, Maim That File`! is a DC coding snack `nAuthor - Target `nLast Updated - April 09 `nCredits - Lanux128 for the original request and feedback `n - Skwire for adding Titans Anchor script `n - Cranioscopical for feedback, feature suggestions, and encouragement return ;###### Session_List: ifnotinstring, sess_list, %myFold% { if sess_list = sess_list:= Myfold else Sess_List.= "|" . myfold } Session_Lst: loop, parse, sess_list, | listindex:= a_index guicontrol,,Curr_Sess, |%sess_List%|| loop { iniread, MRU, MTF.ini, MRU, MRU%a_index% if MRU = ERROR { iniwrite, %myfold%, MTF.ini, MRU, MRU%a_index% Break } else if MRU = %a_space% { iniwrite, %myfold%, MTF.ini, MRU, MRU%a_index% Break } else if MRU = { iniwrite, %myfold%, MTF.ini, MRU, MRU%a_index% Break } else if a_index = 10 { loop, 9 { rdval:= a_index+1 iniread, mru, MTF.ini, MRU, MRU%rdval% iniwrite, %mru%, MTF.ini, MRU, MRU%a_index% } iniwrite, %myfold%, MTF.ini, MRU, MRU10 MRU:= Break } } gosub, MRU_Menu return ;###### ~del:: ~numpaddot:: ~NumpadDel:: guicontrolget, Sel_Cont, focusV if Sel_Cont = Curr_Sess { ifinstring,Sess_List,%Curr_Sess%| stringreplace, Sess_List, Sess_List, %Curr_Sess%|,,All else ifinstring, Sess_List,|%Curr_Sess% stringreplace, Sess_List, Sess_List, |%Curr_Sess%,,All listindex-- guicontrol,,Curr_Sess,| if curr_sess = %MyFold% { MyFold:= gosub, Session_Lst } else gosub, Session_List gosub, refreshMe } Return ;###### ;MRU MRU1: myfold:= a_thismenuitem gosub, Session_List gosub, refreshme return /* MRU2: myfold:= MRU_2 gosub, Session_List gosub, refreshme return */ ;###### MRU_Menu: iniread, MRU, mtf.ini,MRU, MRU1 if MRU = menu, MyMRU, add, %MyFold%, mru1 else { gui, menu menu, MyMRU, deleteall loop,10 { iniread, MRU, mtf.ini,MRU, MRU%A_index% if MRU = ERROR Break else if MRU= Break else if MRU = %a_Space% break else { Mru_%a_index%:= MRU menu, MyMRU, add, %MRU%, mru1 } } gui, menu, mymenubar } return ;############################################################################################# ; ADD FILES + FOLDERS ;############################################################################################# #ifwinactive, Maim That File! ~^O:: Search: fileselectfolder,MyFold,*%myfold%,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 } gosub, refreshme guicontrol,,predef1,0 guicontrol,,predef2,0 guicontrol,,predef3,0 gui, submit, nohide return FMove: if oldfile = %newfile% return filegetattrib, isDir, %MyPath%\%oldfile% ifexist, %MyPath%\%newfile% { msgbox, 8196,,%newfile% exists`, overwrite? { ifmsgbox yes { if isdir = D filemovedir, %MyPath%\%oldfile%, %MyPath%\%newfile%,r else filemove, %MyPath%\%oldfile%, %MyPath%\%newfile%,1 ; LV_modify(MyRow, col1 ,newfile,newlen) if myUndo = myundo:= mypath . "|" . oldfile . "|" . newfile else myundo.= "`n" . mypath . "|" . oldfile . "|" . newfile } } } else { if myUndo = myundo:= mypath . "|" . oldfile . "|" . newfile else myundo.= "`n" . mypath . "|" . oldfile . "|" . newfile 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, +resize +delimiter`n gui, 2:add, listview, r15 w500 grid nosort nosorthdr -wantf2 readonly vUNList,Seq`nPath`nOld Name`nNew Name ;w500 loop, parse, myundo , `n { stringsplit, unArr, a_loopfield, | LV_Add("", a_index, unarr1 , unarr2 , unarr3) } lv_modifycol("",auto) LV_modifyCol(1,"Integer") lv_modifycol(1,"sortDesc") gui, 2:add, button, w50 gSelectAll, All gui, 2:add, button, y243 x70 w50 vNun gSelectNone, None gui, 2:add, button, y243 x130 w50 vAct gUnDone, Undo gui, 2:add, button, y243 x190 w50 vRtn gGoBack, Go Back gui, 2:show, center ;w500 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()) teststring:=unpath . "|" . unold . "|" . unnew . "`n" ifinstring, TestString , %myundo% stringreplace,MyUndo, MyUndo, %unpath%|%unold%|%unnew%`n teststring:="`n" . unpath . "|" . unold . "|" . unnew ifinstring,teststring , %myundo% stringreplace,MyUndo, MyUndo, `n%unpath%|%unold%|%unnew% } Return GoBack: 2guiescape: 2guiclose: gui, 2:destroy gui, 1:default gosub, refreshme gui, show 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% } ;#############################################################################