-
Notifications
You must be signed in to change notification settings - Fork 197
/
clean-folders.py
36 lines (26 loc) · 1.05 KB
/
clean-folders.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Utility script to clean the project files and folders
"""
DELETE_FOLDERS_PATTERNS = ['bin', 'obj']
DELETE_FILES_PATTERNS = ['*.suo', '*.bak', '*.pyc']
import sys, os, fnmatch, shutil
__dir__ = os.path.dirname(os.path.realpath(__file__))
def main():
print __doc__
print "Folders : " + ', '.join(DELETE_FOLDERS_PATTERNS)
print "Files : " + ', '.join(DELETE_FILES_PATTERNS)
print ""
print "Start cleaning ..."
for root_dir, folders, files in os.walk(__dir__):
for del_dir in DELETE_FOLDERS_PATTERNS:
for dirname in fnmatch.filter(folders, del_dir):
dir_path = os.path.join(root_dir, dirname)
print "rm %s" % dir_path
shutil.rmtree(dir_path)
for del_file in DELETE_FILES_PATTERNS:
for filename in fnmatch.filter(files, del_file):
file_path = os.path.join(root_dir, filename)
print "rm %s" % file_path
os.remove(file_path)
print "\nDone"
if __name__ == '__main__':
main()