Add artist to filename with AutoHotkey

A common task I’ve been using AutoHotkey for lately is adding the artist to the filename of an mp3. Here’s some quick code to do that:

RenameSongs(path, artist)
{
	Loop %path%\*.mp3
	{
		IfNotInString A_LoopFileName, %artist%
		{
			newfilename = %artist% - %A_LoopFileName%
			StringReplace newfilename, newfilename, (1),, All
			FileMove %path%\%A_LoopFileName%, %path%\%newfilename%
		}
	}
	TrayTip File rename,Done!
}

Then call it from somewhere else with a path and a proper artist name. How you do that part is up to you, I’m just plugging the values into the script. You could probably make an explorer keyboard shortcut and a box that prompts you for the artist name if you so desired.

Andrew Guyton
http://www.disavian.net/

2 Comments

Tom

I want to add the Artist to the start of the song filename for 1400+ .mp3 files that are in one directory but not on itunes. There is a different Artist in each files properties.

I have never used script like this before. I am using Windows XP

Please advise how I do it?

Andrew Guyton

I’m not exactly sure how to do that, but it sounds like a good thing to be able to do. I don’t see an immediately obvious method, so I might end up using COM or a Windows API call to extract the data from a file.

Leave a Reply