-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccutils.py
68 lines (43 loc) · 1.69 KB
/
ccutils.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
def findFiles(folder_path, filter, find_directory=False, include_sub_directory=True):
find_result = []
filter_list = []
floder_root_count = 0
if len(filter)>0:
filter_list = filter.split(";")
for root, dirs, files in os.walk(folder_path, topdown=True):
if find_directory == True:
for name in dirs:
find_result.append(os.path.join(root, name))
if(include_sub_directory == False):
return find_result
else:
if include_sub_directory == False:
if floder_root_count>0: #如果不找下层目录,则只管第一级目录
continue
for name in files:
file_path = os.path.join(root, name)
for type in filter_list:
if file_path.endswith(type):
find_result.append(file_path)
break
floder_root_count +=1
return find_result
def fileName(file_path, include_suffix=False):
split_result = file_path
if file_path.find('\\') !=-1:
file_path = file_path.replace("\\", "/")
if file_path.find('/') !=-1:
split_result = file_path.split('/')[-1]
if include_suffix ==False:
if file_path.find('.') != -1:
split_result = split_result.split('.')[0]
return split_result
def mkdirs(folder):
if not os.path.exists(folder):
os.makedirs(folder)
if __name__ == '__main__':
folder_path = '数据汇总'
folders = findFiles(folder_path, 'jpg')
for folder in folders:
print(folder)