Created
March 29, 2017 09:23
-
-
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 !!
This file contains hidden or 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
# 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