Skip to content

Instantly share code, notes, and snippets.

@gbrnt
Created September 28, 2014 15:44
Show Gist options
  • Save gbrnt/38790e5f5c0b32439c4c to your computer and use it in GitHub Desktop.
Save gbrnt/38790e5f5c0b32439c4c to your computer and use it in GitHub Desktop.
Tool to count MP3s in a directory and its subdirectories
"""
Tool to count MP3s in a directory and its subdirectories
Created by George Bryant
"""
from os import walk
#Hardcoded folder for now
root_folder = "D:/Music"
file_types = ["mp3", "m4a", "m4p", "wav"]
exclude_types = []
file_count = 0
yes_answers = ["yes", "y"]
for dirpath, dirnames, filenames in walk(root_folder):
for filename in filenames:
file_ext = filename.split(".")[-1].lower()
if file_ext not in file_types and file_ext not in exclude_types:
add_ext = input(("Add files with extension \".{}\" to"
"count? \"y\" for yes, anything else for no. ").format(file_ext)).lower()
if add_ext in yes_answers:
file_types.append(file_ext)
file_count += 1
else:
exclude_types.append(file_ext)
elif file_ext in file_types:
file_count += 1
print("{} files found with the following extensions:".format(file_count))
print(file_types)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment