Skip to content

Instantly share code, notes, and snippets.

@davidandrzej
Created August 1, 2012 04:52
Show Gist options
  • Select an option

  • Save davidandrzej/3223821 to your computer and use it in GitHub Desktop.

Select an option

Save davidandrzej/3223821 to your computer and use it in GitHub Desktop.
Find unexpected directory nesting patterns
"""
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