Skip to content

Instantly share code, notes, and snippets.

@excenter
Created June 19, 2020 22:52
Show Gist options
  • Save excenter/fa658b0029f62166714d4687d65d681e to your computer and use it in GitHub Desktop.
Save excenter/fa658b0029f62166714d4687d65d681e to your computer and use it in GitHub Desktop.
sometimes you need to delete a lot of flacs by extension, and xargs didn't feel right.
import os
def filterExtensions(file):
# change this extension to whatever you need expunged from the directory
filter = ".flac"
if file.endswith(filter):
return True
else:
return False
directory = '.'
files = os.listdir(directory)
filteredFiles = filter(filterExtensions, files)
for file in filteredFiles:
print(file)
path_to_file = os.path.join(directory, file)
os.remove(path_to_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment