Created
August 1, 2012 04:52
-
-
Save davidandrzej/3223821 to your computer and use it in GitHub Desktop.
Find unexpected directory nesting patterns
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 characters
| """ | |
| Script to find folders with bad nesting patterns | |
| (eg, in an arist-album organized music collection) | |
| """ | |
| import os,os.path,sys,shutil,pdb | |
| colroot = sys.argv[1] | |
| skiplist = ['desktop.ini','.DS_Store','Thumbs.db','FINDER.DAT'] | |
| log_f = open('nest_log.txt','w') | |
| def noskip(fn): | |
| return not (fn in skiplist or '.jpg' in fn or '.JPG' in fn | |
| or '.txt' in fn or '.TXT' in fn) | |
| for col in os.listdir(colroot): | |
| c = os.path.join(colroot,col) | |
| if(not os.path.isdir(c)): | |
| if(noskip(col)): | |
| log_f.write('Non-dir %s in %s\n' % (col,colroot)) | |
| continue | |
| for artist in os.listdir(c): | |
| a = os.path.join(c,artist) | |
| if(not os.path.isdir(a)): | |
| if(noskip(artist)): | |
| log_f.write('Non-dir %s in %s\n' % (artist,c)) | |
| continue | |
| for album in os.listdir(a): | |
| alb = os.path.join(a,album) | |
| if(not os.path.isdir(alb)): | |
| if(noskip(album)): | |
| log_f.write('Non-dir %s in %s\n' % (album,a)) | |
| continue | |
| for song in os.listdir(alb): | |
| s = os.path.join(alb,song) | |
| if(os.path.isdir(s)): | |
| log_f.write('Dir %s in %s\n' % (song,alb)) | |
| log_f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment