Created
July 20, 2010 12:36
-
-
Save cherian/482899 to your computer and use it in GitHub Desktop.
Revisions
-
cherian created this gist
Jul 20, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ import sys import os , shutil rootdir = None try: rootdir = sys.argv[1] except IndexError: print 'Directory not specified. Specify it in the format ' + sys.argv[0] + ' c:\songs' sys.exit() if not os.path.isdir(rootdir): print 'argument is not not a directory' sys.exit() dirDict = {} for root,dirs,files in os.walk(rootdir): for file in files: print file rootfilepath = os.path.join(rootdir, file) album = file.partition('-')[0].strip() if not dirDict.has_key(album): dirDict[album] = [rootfilepath] else: albumfiles = dirDict.get(album) albumfiles.append(rootfilepath) for k,v in dirDict.iteritems(): albumDir = os.path.join(rootdir, k) if not os.path.exists(albumDir): os.mkdir(albumDir) for file in v: print 'album dir is ' + albumDir print 'copying ' + file + ' to directory ' + albumDir try: shutil.move(file.strip(),albumDir) except IOError: print 'Could not copy ' + file + 'to ' + albumDir