Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- # -*- coding: utf-8 -*-
- import os
- import sys
- total_count = 0
- files = []
- exec_size = 0
- total_size = 0
- desired_type = 'x-executable; charset=binary'
- def check(path):
- global total_count, exec_size, total_size
- total_count += 1
- size = os.stat(path).st_size
- total_size += size
- cmd = "file -i '%s' | grep '%s' > /dev/null"
- if not os.system(cmd % (path, desired_type)):
- files.append(path)
- exec_size += size
- print path
- def find(directory):
- for name in os.listdir(directory):
- path = os.path.join(directory, name)
- if os.path.isdir(path):
- find(path)
- elif os.path.isfile(path):
- check(path)
- base = 1024 ** 2
- print '[*] Search for files...'
- directory = sys.argv[1] if len(sys.argv) >= 2 else os.path.curdir
- find(directory)
- label = '[*] Directory contains %s files (total size %.1lf Mb)'
- print label % (total_count, total_size / float(base))
- label = '[?] Are you sure to remove %s files (total size %.1lf Mb)? [yes/no]'
- print label % (len(files), exec_size / float(base))
- if raw_input() == 'yes':
- for path in files:
- os.remove(path)
- print '[+] Operation complete'
- else:
- print '[*] Operation canceled'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement