AHK batch rename files script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rebsby
Posts: 3
Joined: 03 Dec 2022, 10:50

AHK batch rename files script

Post by rebsby » 03 Dec 2022, 10:58

Hello, thank you for taking the time to read my post.

I have a large list of .mp3 files, each one named differently. However, there is one character that shows up in every file.
What I would like to do is rename the file as to where any text before said character is removed, and the rest is kept as is.

Example:
Before: Artist - Title.mp3
After: Title.mp3

Would this be possible with AutoHotKey? If so, how would I go about achieving it?
Please note that I am not too experienced with AHK, and also slightly dumb.

User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: AHK batch rename files script

Post by boiler » 03 Dec 2022, 11:03

Yes, this is straightforward using RegExReplace or InStr with SubStr.

It seems you’d want to also remove the space after that character as well. Trim can help with that if it doesn’t always have a following space (although the RegExReplace method can handle it directly).

User avatar
boiler
Posts: 16963
Joined: 21 Dec 2014, 02:44

Re: AHK batch rename files script

Post by boiler » 03 Dec 2022, 11:08

You would also use Loop, Files and FileMove.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: AHK batch rename files script

Post by swagfag » 03 Dec 2022, 11:10

just use Bulk Rename Utility instead

User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: AHK batch rename files script  Topic is solved

Post by mikeyww » 03 Dec 2022, 11:15

Code: Select all

dir = %A_ScriptDir%\t
Loop, Files, %dir%\*.mp3
 FileMove, %A_LoopFilePath%, % dir "\" Trim(SubStr(A_LoopFileName, Instr(A_LoopFileName, "-") + 1))
MsgBox, 64, Done, Done!

rebsby
Posts: 3
Joined: 03 Dec 2022, 10:50

Re: AHK batch rename files script

Post by rebsby » 03 Dec 2022, 12:23

mikeyww wrote:
03 Dec 2022, 11:15

Code: Select all

dir = %A_ScriptDir%\t
Loop, Files, %dir%\*.mp3
 FileMove, %A_LoopFilePath%, % dir "\" Trim(SubStr(A_LoopFileName, Instr(A_LoopFileName, "-") + 1))
MsgBox, 64, Done, Done!
Thank you for your reply!

This worked perfectly, although I had to remove the \t on the first line to get it to work, unsure why that is. Either way, your help is greatly appreciated! :salute:

rebsby
Posts: 3
Joined: 03 Dec 2022, 10:50

Re: AHK batch rename files script

Post by rebsby » 03 Dec 2022, 12:26

boiler wrote:
03 Dec 2022, 11:03
Yes, this is straightforward using RegExReplace or InStr with SubStr.

It seems you’d want to also remove the space after that character as well. Trim can help with that if it doesn’t always have a following space (although the RegExReplace method can handle it directly).
Thank you for your reply!

I have read through the wiki pages and I understand how I could've done this now. Your response was very useful, thank you!

User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: AHK batch rename files script

Post by mikeyww » 03 Dec 2022, 12:29

You can use any directory of your choice! (Yeah, I just did what boiler said!)

Post Reply

Return to “Ask for Help (v1)”