While I’m at it…

Hell, if I’m doing file maintenance, I may as well go all the way.

My music files were all in “$Artist – $Album” folders, and I decided I wanted them in “$Artist/$Artist – $Album” format instead.

A quick regex and a Python script later, and I’m set.

#!/usr/bin/python
#Written by Benjamin Kenneally
#05/29/11

import re
import os

directs = os.listdir((os.getcwd()))
for folder in directs:
	match = re.search('(^.+)[ ]-[ ].+.*', folder)
	if match:
		band = match.group(1)
		newFolderstruct = "%s/%s" % (band, folder)
		os.renames('%s'% (folder),'%s' % (newFolderstruct))
		print "Moving %s to %s." % (folder, newFolderstruct)
	else:
		print "No change is being made to %s." % (folder)

I still always feel like my RegEx is horrible and sloppy, but it gets the job done. A simple script, sure, but I had to look at the

match.group

usage again to make sure I had it down. More practice can’t hurt, right?

Advertisements

~ by Benjamin Kenneally on May 29, 2011.

One Response to “While I’m at it…”

  1. Good day! I simply want to give an enormous thumbs up for the good info youˇ¦ve here on this post.
    I will likely be coming again to your weblog for more soon.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

 
%d bloggers like this: