/* desc - basic file renamer. filter (listed) files by length. Apply several predefined actions Auth - Target Updated - Mar09 * 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 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, 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 gRerun, 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, y40 x545 vtxt1, Start Pos guicontrol,hide, txt1 gui, add, checkbox, y40 x525 vPreDef1 gsetme checked0, Trim left gui, add, edit, y36 x600 w45 vLTrim gSetMe gui, add, updown, range1-256,1 gui, add, text, y90 x550 vtxt2, # Chars guicontrol, hide, txt2 gui, add, checkbox, y90 x525 vPreDef2 gsetme checked0, Trim Right gui, add, edit, y86 x600 w45 vRTrim gSetMe gui, add, updown, range1-256,1 gui, add, checkbox, y65 x555 vMidStr gsetme checked0, Mid gui, add, groupbox, y115 x520 w180 h140 gui, add, Checkbox, y127 x525 vPreDef3 gsetme checked0, Custom Replace gui, add, edit, y145 x525 w170 vFindMe gSetMe Gui, add, text, y170 x525, enter search characters or strings `nin comma separated format gui, add, edit, y200 x525 w170 vRepMe gSetMe Gui, add, text, y220 x525, enter replacement character or `nstring (one only) gui, add, button, y6 x525 w170 gPreDef, Apply gui, add, button, y260 x525 w170 gUndoMe, 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 ;############################################################################################# ;############################################################################################# #F10::reload Quit: #F12:: guiclose: exitapp return Open: return 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 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 gui, submit, nohide } else if midstr = 0 { guicontrol,hide,txt1 guicontrol,hide,txt2 guicontrol,show,predef1 guicontrol,show,predef2 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, 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: /* sort, MyMRU, u loop, parse, mymru, `n ListCount:= a_index if ListCount > 10 { listcount-= 9 loop, parse, MyMRU, `n { if a_index > ListCount { tmpMRU.= a_loopfield . "`n" mruindex:= a_index - listcount iniwrite, a_loopfield,mtf.ini,mru,mru%mruindex% } } } msgbox, %myMRU% ;iniwrite, %MyMRU%,mtf.ini,MRU,MRUList */ return ;############################################################################################# ; ADD FILES + FOLDERS ;############################################################################################# Search: fileselectfolder,MyFold,::{20d04fe0-3aea-1069-a2d8-08002b30309d},2 If errorlevel return rerun: if myfold = ::{20d04fe0-3aea-1069-a2d8-08002b30309d} return if myfold = return ;myMRU.= myfold . "`n" ;gosub MRU gosub, clearList 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 ;############################################################################################# $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 ;############################################################################################# UndoMe: ; return gui, hide ;gui, 2:+owner1 ;gui, 2:+owned 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