#save me as countMp3s.py from fnmatch import fnmatch import os import sys if len(sys.argv) < 2: print "Please supply a path argument; this is the folder path to your music folder" exit(1) path = sys.argv[1] total_mp3s = 0 total_folders = 0 total_weird_folders = 0 for (sub_path, folders, files) in os.walk(path): mp3files = [x for x in files if fnmatch(x, "*.mp3")] total_mp3s += len(mp3files) total_folders += 1 if len(folders) > 0 and len(mp3files) > 0: print sub_path total_weird_folders += 1 fraction_weird_folders = 0 if total_folders > 0: fraction_weird_folders = total_weird_folders / float(total_folders) print "Total number of mp3s: %d" % total_mp3s print "Number of folders with mp3s and subfolders: %d" % total_weird_folders print "Total number of folders: %d" % total_folders print "Fraction of folders with mp3s and subfolders: %f" % fraction_weird_folders