Skip to content

Instantly share code, notes, and snippets.

@vinovator
Created March 29, 2017 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinovator/207b7e643ea75a6462e3326a74e1a5f6 to your computer and use it in GitHub Desktop.
Save vinovator/207b7e643ea75a6462e3326a74e1a5f6 to your computer and use it in GitHub Desktop.
Find files of a specific extension from a root directory and delete them !!
# wma_finder.py
# Python 3.5
import os
path = "D:\Vinoth\Songs"
file_extn = ".wma
file_count = 0
with open(path + "\wma_deleted.txt", "a") as del_log:
for root, dirs, files in os.walk(path):
for file in files:
name, extn = os.path.splitext(file)
if extn == file_extn:
file_count += 1
print("{0}. Deleting {1}\{2}".format(file_count, root, file))
del_log.write("{0}. Deleting {1}\{2}\n".format(file_count, root, file))
# Careful - deleting file
os.remove(root + "\\" + file)
del_log.write("{} files deleted".format(file_count))
print("{} files deleted".format(file_count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment