Last active
August 24, 2016 14:41
-
-
Save DavidHickman/4fa5025bad340ebadad1af6842d50846 to your computer and use it in GitHub Desktop.
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
import os | |
def clean_up_folder(dir_path, ext_keep=(".zip", ".kmz", ".GeoJSON", ".csv")): | |
""" | |
Loop through a directory looking for files with extensions | |
that match an extension in an array. If the file's extension | |
does not match, delete the file. | |
:param dir_path: (str) path to directory to search | |
:param ext_keep: (list) file extensions of files to keep | |
:return: None | |
""" | |
ext_keep = [ext.lower() for ext in ext_keep] | |
for f in os.listdir(dir_path): | |
if os.path.splitext(f)[1].lower() not in ext_keep: | |
os.remove(os.path.join(dir_path, f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment