Created
January 8, 2013 17:27
-
-
Save anonymous/4485837 to your computer and use it in GitHub Desktop.
A little script that recurses into the subdirectories of a specified folder and reports the numbers of filenames containing the specified file extension in each base-directory folder. I use it to find which of my Music library's artist folders contain the most mp3s and m4as. so I could focus on replacing those with oggs. Usage: $ countfiles ~/Mu…
This file contains 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
#!/usr/bin/env python3 | |
import os | |
from sys import argv | |
# Walk through folders recursively, list the full path and number of (extension) files found in each. | |
basefolder = os.path.expanduser(argv[1]) | |
filetype = str(argv[2]).lower() | |
output = [] | |
# New system: | |
for folder in os.listdir(basefolder): | |
filecounter = 0 | |
for subf, childf, files in os.walk(os.path.join(basefolder,folder)): | |
for filen in files: | |
if filetype in filen.lower(): | |
filecounter += 1 | |
if filecounter: | |
#print(folder, "contains {0} mp3s.".format(filecounter)) | |
output.append([filecounter, folder]) | |
# As first list item is an integer, will be sorted by this. Largest last. | |
output.sort() | |
print("Count, Path") | |
for x in output[:]: | |
newx = str(x[0]) + "\t" + x[1] | |
output[output.index(x)] = newx | |
print("\r\n".join(output)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment