Advertisement
Guest User

Python - Remove files by extension

a guest
Aug 10th, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import os
  2.  
  3. def remove_by_ext(path,ext):
  4. '''Walks through directories removing files with specified extension'''
  5.     for (path,dirs,files) in os.walk(path):
  6.         for file_name in files:
  7.             file_name_lower=file_name.lower()
  8.             if file_name_lower[-len(ext):] == ext.lower():
  9.                 os.remove(path+'\\'+file_name)
  10.                 print('File removed: %s' %file_name)
  11.  
  12. path = raw_input('Input Path: ')
  13. ext = raw_input('Input Extension: ')
  14. remove_by_ext(path,ext)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement