-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab1.py
More file actions
54 lines (40 loc) · 1.33 KB
/
lab1.py
File metadata and controls
54 lines (40 loc) · 1.33 KB
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
# Govinda KC
# CS 2302 10:30 am class
# Lab 1
import os
import random
def get_dirs_and_files(path):
dir_list = [path + '/' + directory for directory in os.listdir(path) if os.path.isdir(path + '/' + directory)]
file_list = [path+ '/' + directory for directory in os.listdir(path) if not os.path.isdir(path + '/' + directory)]
return dir_list, file_list
def classify_pic(path):
if "dog" in path:
return 0.5 + random.random() / 2
return random.random() / 2
def process_dir(path):
path = os.path.abspath(path)
cat_list = []
dog_list = []
dir_list, file_list = get_dirs_and_files(path)
dir_list = [os.path.abspath(d) for d in dir_list]
file_list = [os.path.abspath(f) for f in file_list]
#print(dir_list, file_list)
for _file in file_list:
if classify_pic(_file) > 0.5:
dog_list.append(_file)
elif 'cat' in _file:
cat_list.append(_file)
if len(dir_list) > 0:
for _dir in dir_list:
#print(_dir)
new_cats, new_dogs = process_dir(_dir)
cat_list.extend(new_cats)
dog_list.extend(new_dogs)
return cat_list, dog_list
def main():
start_path = './' # current directory
cats, dogs = process_dir(start_path)
print("CATS_list: ", cats)
print()
print("DOGS_list: ", dogs)
main()