Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Multi-File Renamer Script
#IfWinActive ahk_exe explorer.exe
^m::
; CLEAR VARIABLES
clipboard = ; clear variable
Sleep, 100 ; allow time for clipboard variable to empty
; COPY FILENAMES (AND PATHS) & STRIP QUOTATION MARKS
; Line below: ^+c would not work. Required awkward method below
Send, {Control Down}{Shift Down}c{Shift Up}{Control Up} ; copies selected filenames in explorer to clipboard
Sleep, 100
StringReplace, QuotesStripped, Clipboard, `",,all ; strip out quotation marks
; "QuoteStripped" variable now has all selected path with filenames listed w/o quotes
; SEPARATE EACH COPIED FILENAME/PATH INTO AN ARRAY VARIABLE
; Next: StrSplit lines (each copies Path/Filename) in the clipboard to array variables
OrigFileArray := StrSplit(QuotesStripped, "`n")
F_Array_Len := OrigFileArray.MaxIndex()
; At this point we have OrigFileArray[1] through [6]
; SPLIT EACH COPIED PATH/FILENAME INTO SEPARATE PATH ELEMENTS
; Next: Split the original path/filenames into separate elements
; Line below: syntax of splitpath
; SplitPath, input variable, filename only with ext, path w/o filename, file extension, filename w/o ext, drive
SplitPath, % OrigFileArray[1], fname_with_ext1, fdir1, fext1, fname_no_ext1, fdrv1
;MsgBox, fname_with_ext1: %fname_with_ext1%`nfdir1: %fdir1%`nfext1: %fext1%`nfname_no_ext1: %fname_no_ext1%`nfdrv1: %fdrv1%
SplitPath, % OrigFileArray[2], fname_with_ext2, fdir2, fext2, fname_no_ext2, fdrv2 ;note fdir1, fdir2, etc. are the same
SplitPath, % OrigFileArray[3], fname_with_ext3, fdir3, fext3, fname_no_ext3, fdrv3
SplitPath, % OrigFileArray[4], fname_with_ext4, fdir4, fext4, fname_no_ext4, fdrv4
SplitPath, % OrigFileArray[5], fname_with_ext5, fdir5, fext5, fname_no_ext5, fdrv5
SplitPath, % OrigFileArray[6], fname_with_ext6, fdir6, fext6, fname_no_ext6, fdrv6
; Convert Array variables to normal variables because I don't like working with arrays
OrigPathFile1 := OrigFileArray[1]
OrigPathFile2 := OrigFileArray[2]
OrigPathFile3 := OrigFileArray[3]
OrigPathFile4 := OrigFileArray[4]
OrigPathFile5 := OrigFileArray[5]
OrigPathFile6 := OrigFileArray[6]
;MsgBox, OrigFilePath's:`n%OrigPathFile1%`n%OrigPathFile2%`n%OrigPathFile3%
; GUI TO LIST FILES (w/o PATHS TO AVOID GUI CLUTTER)
gui, Font, s12, Verdana ; smaller font for the hotstring/hotkey references
gui, add, text, x20, Ctrl-Alt-D - Today's Date
gui, add, text, x20 y+5, F10 - Date Picker
gui, add, text, x20 y+5, Ctrl-1 - 1_Prelim
gui, add, text, x20 y+5, Ctrl-2 - 2_PreClose
gui, add, text, x20 y+5, Ctrl-3 - 3_PostClose
gui, add, text, x350 y10, Number of files listed: %F_Array_Len%
gui, add, text, x350 y40, Current Path: %fdir1%
gui, Font, s16, Verdana ; bigger font for the edit boxes
gui, add, text, x350 y70, Prefix:
gui, add, edit, x430 w400 y70 vPrefix ; edit box for adding a common prefix to the filenames
gui, Font, s16, Verdana ; again, bigger font for the edit boxes
gui, add, edit, x20 w850 y120 vNewFile1, % fname_no_ext1 ; 1st edit box with existing filename as default entry
gui, add, text, x+10 w50, %fext1% ; add the file extenstion as a text after the filename edit box
gui, add, edit, x20 y+10 w850 vNewFile2, % fname_no_ext2
gui, add, text, x+10 w50, %fext2%
gui, add, edit, x20 y+10 w850 vNewFile3, % fname_no_ext3
gui, add, text, x+10 w50, %fext3%
gui, add, edit, x20 y+10 w850 vNewFile4, % fname_no_ext4
gui, add, text, x+10 w50, %fext4%
gui, add, edit, x20 y+10 w850 vNewFile5, % fname_no_ext5
gui, add, text, x+10 w50, %fext5%
gui, add, edit, x20 y+10 w850 vNewFile6, % fname_no_ext6
gui, add, text, x+10 w50, %fext6%
; add button
gui, add, button, x20 gRenameToSameFolder, Rename -Same Folder
gui, show, autosize, Multi-File Saver ; Gui name at top of window is Multi-File Saver
return ; return for gui
; Note: at this point, FileArray[n] is original filename, NewFile1, etc. is new filename
; GUI BUTTON SUBROUTINES
RenameToSameFolder: ; gui button subroutine
gui, submit, nohide
TargetFolder := fdir1 . "\" ; Note: fdir1, fdir2, etc. are all the same (it's the path only)
; create a variable Proposed[n] to shorten new paths and destination into one variable
; but only for the number of files chosen, otherwise leave Proposed[n] variable blank
; "Proposed[n]" variable is the filename plus the file extension
If (NewFile1 != "")
Proposed1 := Prefix . NewFile1 . "." . fext1
If (NewFile2 != "")
Proposed2 := Prefix . NewFile2 . "." . fext1
If (NewFile3 != "")
Proposed3 := Prefix . NewFile3 . "." . fext1
If (NewFile4 != "")
Proposed4 := Prefix . NewFile4 . "." . fext1
If (NewFile5 != "")
Proposed5 := Prefix . NewFile5 . "." . fext1
If (NewFile6 != "")
Proposed6 := Prefix . NewFile6 . "." . fext1
; RENAME COMMANDS.
MsgBox, You've reached the rename commands.
Sleep, 1000
If (NewFile1 != "")
{
MsgBox, About to rename first file:`n%OrigPathFile1%`nto`n%TargetFolder%%Proposed1%
Sleep, 1000
FileMove, %OrigPathFile1%, %TargetFolder%%Proposed1%
Sleep, 1000
}
If (NewFile2 != "")
{
MsgBox, About to rename second file:`n%OrigPathFile2%`nto`n%TargetFolder%%Proposed2%
Sleep, 1000
FileMove, %OrigPathFile2%, %TargetFolder%%Proposed2%
Sleep, 2000
}
If (NewFile3 != "")
{
MsgBox, About to rename third file:`n%OrigPathFile3%`nto`n%TargetFolder%%Proposed3%
Sleep, 1000
FileMove, %OrigPathFile3%, %TargetFolder%%Proposed3%
Sleep, 1000
}
If (NewFile4 != "")
{
MsgBox, About to rename fourth file:`n%OrigPathFile4%`nto`n%TargetFolder%%Proposed4%
Sleep, 1000
FileMove, %OrigPathFile4%, %TargetFolder%%Proposed4%
Sleep, 1000
}
If (NewFile5 != "")
{
MsgBox, About to rename fifth file:`n%OrigPathFile5%`nto`n%TargetFolder%%Proposed5%
Sleep, 1000
FileMove, %OrigPathFile5%, %TargetFolder%%Proposed5%
Sleep, 1000
}
If (NewFile6 != "")
{
MsgBox, About to rename sixth file:`n%OrigPathFile6%`nto`n%TargetFolder%%Proposed6%
Sleep, 1000
FileMove, %OrigPathFile6%, %TargetFolder%%Proposed6%
Sleep, 1000
}
Gui, Destroy
return ; return for RenameToSameFolder subroutine
GuiClose:
GuiEscape:
Gui, Destroy
return
return ; return for hotkey trigger (^m")