Hi i am new to autohotkey. i am looking to make a Renamer.
I want to do few things
Search For Copy and delete it
"Regular2_Alpha_Button_copy"--- removes copy--- "Regular2_Alpha_Button"
Search For Alpha and replace it with Mask
"Regular2_Alpha_Button" ----replace Alpha -- "Regular2_Mask_Button"
Search For name and take input then replace it
"Regular2_Mask_Button"----take input from user and replace---- "Regular2" with the user input.
Thanks in advance
AutoHotKey Renamer Topic is solved
AutoHotKey Renamer
Last edited by arpit12 on 12 Apr 2022, 14:49, edited 1 time in total.
Re: AutoHotKey Renamer
Regular2_Alpha_Button_copy removes copy Regular2_Alpha_Button - FileDelete
Regular2_Alpha_Button replace Alpha -- Regular2_Mask_Button - FileMove
Regular2_Mask_Button----take input from user and replace Regular2 with the user input. - InputBox + FileMove
Regular2_Alpha_Button replace Alpha -- Regular2_Mask_Button - FileMove
Regular2_Mask_Button----take input from user and replace Regular2 with the user input. - InputBox + FileMove
Re: AutoHotKey Renamer
Hi,
@BoBo I am looking to rename the file but fileDelete and fileMove work on whole file.
@BoBo I am looking to rename the file but fileDelete and fileMove work on whole file.
Re: AutoHotKey Renamer
@arpit12 -
FileMove
Moves or renames one or more files.
Re: AutoHotKey Renamer
Sorry as i have mentioned i am new to coding. If anyone can provide me with syntax that would be very helpful.
Re: AutoHotKey Renamer
arpit12 wrote: Sorry as i have mentioned i am new to coding. If anyone can provide me with syntax that would be very helpful.
https://www.autohotkey.com/docs/commands/FileMove.htm#ExRename
Use the docs.#2: Renames a single file.Code: Select all
FileMove, C:\File Before.txt, C:\File After.txt
Re: AutoHotKey Renamer
Hi @Cuadrix
Thanks but i saw this syntax in docs but as you see here they have given full path of the file but what i am looking for is that program search for particular word and replace it with another Like search for alpha and replace with Mask.
Thanks but i saw this syntax in docs but as you see here they have given full path of the file but what i am looking for is that program search for particular word and replace it with another Like search for alpha and replace with Mask.
Re: AutoHotKey Renamer
Untested. Press F1 to "Search For name and take input then replace it"
Code: Select all
SetWorkingDir %A_ScriptDir%
Prefix := "Regular2"
Suffix := "copy"
OldText := "Alpha"
NewText := "Mask"
_ := "_" ; Separator
; Loop through all files in each subdirectory
Loop, Files, *, R
{
; Remove copies
if (InStr(A_LoopFilePath, _ Suffix)) {
FileDelete, % A_LoopFilePath
; Rename "Alpha" to "Mask"
} else if (InStr(A_LoopFilePath, _ OldText _)) {
FileMove, % A_LoopFilePath, % StrReplace(A_LoopFilePath, _ OldText _, _ NewText _)
}
}
F1::
; Manual user input triggered on hotkey press
InputBox, FileToSearch,, % "File to search (path relative to working directory):"
InputBox, NewPrefix,, % "Replace " Prefix " with:"
; Rename file according to the input
FileMove, % FileToSearch, % StrReplace(FileToSearch, Prefix _, NewPrefix _)
Return
Re: AutoHotKey Renamer
Hi,
@Cuadrix Thank for the help
I tested the code but
filedelete is deleting the whole file.
Second function works fine it is replacing
third function also not working it does nothing.
@Cuadrix Thank for the help
I tested the code but
filedelete is deleting the whole file.
Second function works fine it is replacing
third function also not working it does nothing.
Re: AutoHotKey Renamer
I see now. Replace "copy" not delete the file...
Try this:
The 3rd function should work just fine
Try this:
Code: Select all
SetWorkingDir %A_ScriptDir%
Prefix := "Regular2"
Suffix := "copy"
OldText := "Alpha"
NewText := "Mask"
_ := "_" ; Separator
; Loop through all files in each subdirectory
Loop, Files, *, R
{
; Remove "copy" suffix
FileName := StrReplace(A_LoopFilePath, _ Suffix)
; Replace "Alpha" with "Mask"
FileName := StrReplace(FileName, _ OldText _, _ NewText _)
; Finally rename the file
FileMove, % A_LoopFilePath, % FileName
}
F1::
; Manual user input triggered on hotkey press
InputBox, FileToSearch,, % "File to search (path relative to working directory):"
InputBox, NewPrefix,, % "Replace " Prefix " with:"
; Rename file according to the input
FileMove, % FileToSearch, % StrReplace(FileToSearch, Prefix _, NewPrefix _)
Return
Re: AutoHotKey Renamer
Thanks @Cuadrix this works.
Is it possible to multiple value to
Suffix := "copy"
Also the third function only works if I gave the name of the file like
Regular2_Mask_Button.jpg in "path relative to working directory"
would it be possible if it takes prefix as input and search the same folder as it is doing for first two function and replace by new input.
Is it possible to multiple value to
Suffix := "copy"
Also the third function only works if I gave the name of the file like
Regular2_Mask_Button.jpg in "path relative to working directory"
would it be possible if it takes prefix as input and search the same folder as it is doing for first two function and replace by new input.
Re: AutoHotKey Renamer
Code: Select all
SetWorkingDir %A_ScriptDir%
FileList := []
Prefix := "Regular2"
SuffixList := ["copy", "dragon", "banana"]
OldText := "Alpha"
NewText := "Mask"
_ := "_" ; Separator
; Loop through all files in each subdirectory
Loop, Files, *, R
{
; Shorten because too much eye cancer
LFP := A_LoopFilePath
; Skip if prefix not in the beginning of file name
If (InStr(LFP, Prefix _) != 1)
continue
; Remove "copy..." suffix
For Idx, Suffix in SuffixList
{
Length := StrLen(LFP) - StrLen(_ Suffix)
If (InStr(LFP, _ Suffix, Length)) {
FileName := SubStr(LFP, 1, Length)
break
}
}
; Replace "Alpha" with "Mask"
FileName := StrReplace(FileName, _ OldText _, _ NewText _)
; Finally rename the file
If (FileName) {
FileMove, % LFP, % FileName
; Add file to list for manual operation later
FileList.Push(FileName)
break
}
}
F1::
; Manual user input triggered on hotkey press
InputBox, OldPrefix,, % "File to search (prefix)(path relative to working directory):"
InputBox, NewPrefix,, % "Replace " OldPrefix " with:"
For Idx, File in FileList
{
If (InStr(File, OldPrefix)) {
; Rename file according to the input
FileMove, % File, % StrReplace(File, OldPrefix _, NewPrefix _)
}
}
Return
Re: AutoHotKey Renamer
Code is not working anymore.it does nothing.
Re: AutoHotKey Renamer
Hi
@Cuadrix I copied the code and run
this is my file name :: Regular2_Alpha_Button_Copy.jpg
it is not doing anything.
Also two input box so first should i give like Regular2 and then Regular3
Let me know if i am doing anything wrong here.
Thanks
@Cuadrix I copied the code and run
this is my file name :: Regular2_Alpha_Button_Copy.jpg
it is not doing anything.
Also two input box so first should i give like Regular2 and then Regular3
Let me know if i am doing anything wrong here.
Thanks
Re: AutoHotKey Renamer Topic is solved
Just press F1 again to search for "Regular3". Just remember to add it to the PrefixList
Code: Select all
SetWorkingDir %A_ScriptDir%
FileList := []
PrefixList := ["Regular2", "Regular3"]
SuffixList := ["copy", "dragon", "banana"]
OldText := "Alpha"
NewText := "Mask"
_ := "_" ; Separator
; Loop through all files in each subdirectory
Loop, Files, *, R
{
SplitPath, A_LoopFilePath,, FileDir, FileExt, FileName
; Skip if prefix not in the beginning of file name
For Idx, Prefix in PrefixList
{
; Get back to main outerloop if prefix exists
If (InStr(FileName, Prefix _) = 1)
Break
; Skip if reached end of list and still no prefix
Else If (Idx = PrefixList.Length())
Continue, 2
}
; Remove "copy..." suffix
For Idx, Suffix in SuffixList
{
Length := StrLen(FileName) - StrLen(_ Suffix)
If (InStr(FileName, _ Suffix, Length)) {
FileName := SubStr(FileName, 1, Length)
Break
}
}
; Replace "Alpha" with "Mask"
FileName := StrReplace(FileName, _ OldText _, _ NewText _)
If (FileName) {
; Remember to join dir, ext and name back together
If (FileDir)
FileName := FileDir "\" FileName
If (FileExt)
FileName := FileName "." FileExt
; Finally rename the file
FileMove, % A_LoopFilePath, % FileName
; Add file to list for manual operation later
FileList.Push(FileName)
}
}
F1::
; Manual user input triggered on hotkey press
InputBox, OldPrefix,, % "File to search (prefix)(path relative to working directory):"
InputBox, NewPrefix,, % "Replace " OldPrefix " with:"
For Idx, File in FileList
{
If (InStr(File, OldPrefix)) {
; Rename file according to the input
FileMove, % File, % StrReplace(File, OldPrefix _, NewPrefix _)
}
}
Return
Re: AutoHotKey Renamer
Thank you so much it works.
Re: AutoHotKey Renamer
Hi,
@Cuadrix
Please help i need few changes to this code. I want to remove the prefix also but before removing prefix would it be possible to create the folder and move same files and then remove the prefix
Like::
Regular2_Alpha_Button_copy
Regular2_Alpha_Rivet_copy
Regular3_Alpha_Button_copy
Regular3_Alpha_Rivet_copy
So in this case it would create two folder with name Regular2 & Regula3
and inside file naming would be
Mask_Button
Mask_Rivet
If it would be possible without user input.
Thank you in advance.
@Cuadrix
Please help i need few changes to this code. I want to remove the prefix also but before removing prefix would it be possible to create the folder and move same files and then remove the prefix
Like::
Regular2_Alpha_Button_copy
Regular2_Alpha_Rivet_copy
Regular3_Alpha_Button_copy
Regular3_Alpha_Rivet_copy
So in this case it would create two folder with name Regular2 & Regula3
and inside file naming would be
Mask_Button
Mask_Rivet
If it would be possible without user input.
Thank you in advance.
Who is online
Users browsing this forum: VanVarden and 103 guests