-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.py
40 lines (34 loc) · 1.25 KB
/
clean.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
37
38
39
40
#!/usr/bin/env python
import os
import shutil
import sys
# Check if directory to be cleanup provided in command line arguments
# Else take current command line path as a default root directory path
if len(sys.argv) > 1:
rootDir = sys.argv[1]
else:
rootDir = os.getcwd()
# Defined directory to be removed
rmDirs = ["build", ".gradle", ".settings", ".cxx", ".idea", ".externalNativeBuild"]
# Defined file extensions to be removed
rmFiles = '.iml'
# Iterate to Root Directory
for root, subDirs, files in os.walk(rootDir):
for dir in subDirs:
if dir in rmDirs:
try:
shutil.rmtree(os.path.join(root, dir))
print("Delete Directory: " + os.path.join(root, dir))
except FileNotFoundError as err:
# Print error and continue
print(err)
print("Delete Failed: " + os.path.join(root, dir))
for file in files:
if file.endswith(rmFiles):
try:
os.remove(os.path.join(root, file))
print("Delete File: " + os.path.join(root, file))
except FileNotFoundError as err:
# Print error and continue
print(err)
print("Delete Failed: " + os.path.join(root, file))