-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper.py
49 lines (35 loc) · 936 Bytes
/
helper.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
41
42
43
44
45
46
47
48
49
import os
import shutil
def delete_folder(path):
folder_paths = [root for root,dirs,files in os.walk(path)]
for folder_path in folder_paths:
if 'equal' in folder_path:
print folder_path
try:
shutil.rmtree(folder_path)
except:
print '*'+folder_path
def add_gitignore(path):
folder_paths = [root for root,dirs,files in os.walk(path)]
for folder_path in folder_paths:
file_path = folder_path+'/.gitignore'
if os.path.exists(file_path):
print '*'+file_path
return
file = open(file_path,'w')
content = '*.jpg\n*.png\n'
file.write(content)
print file_path
file.close()
def file_counts(path):
for root,dirs,files in os.walk(path):
num_files = len(files)
if num_files==0:
num_files = sum([len(f) for r,d,f in os.walk(root)])
print root,':',num_files
if __name__ == '__main__':
# path = '.'
# add_gitignore(path)
path = 'data/'
file_counts(path)
# delete_folder(path)