Leere Verzeichnisse finden

Zum aufräumen meiner mp3 Sammlung hab ich ein Python Script geschrieben, welches leere Verzeichnisse findet:

#!/usr/bin/python

from os import path, listdir
from sys import argv, stderr

count=0

def find(dr):
    global count
    count+=1
    stderr.write("\rscanned "+count.__str__()+" dirs\r")
    stderr.flush()
    try:
        filelist=listdir(dr)
        if len(filelist) == 0:
            print "\'"+dr+"\'"
    except:
        filelist=[]
        stderr.write("could not read " + dr + "\n")
        stderr.flush()
    for file in filelist:
        df=path.join(dr,file)
        if path.isdir(df):
            find(df)

try:
    find(argv[1])
except:
    pass

Leave a Reply

Your email address will not be published. Required fields are marked *