-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathio_handler.py
78 lines (60 loc) · 2 KB
/
io_handler.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
69
70
71
72
73
74
75
76
77
78
"""
3D pose estimation of an RGB-D camera using least squares technique
Created on Aug 2016
Updated on May 2019
By Sina M.Baharlou ([email protected])
Web page: www.sinabaharlou.com
"""
# -- Import required libraries --
import os
# -- Io Handler class --
class IoHandler:
# -- Constructor --
def __init__(self, path):
self.__path = path # -- working path
self.__list = list() # -- file list
self.__current_index = 0 # -- current index
# -- Clear file list --
def clear_list(self):
self.__list = list()
self.__current_index = 0
# -- Load all files --
def load_files(self, extension, l_sorted=False):
file_count = 0
# -- Loop through all files --
for file in os.listdir(self.__path):
if file.endswith(extension):
self.__list.append(file)
file_count += 1
# -- Sort the files if it's needed --
if l_sorted:
self.__list.sort()
return file_count
# -- Get the next file --
def next_file(self, append_path=True):
# -- Check if it has reached the end --
if self.__current_index >= len(self.__list):
return None
# -- Get the filename --
filename = self.__list[self.__current_index]
# -- Append with path if it's needed --
if append_path:
filename = self.__path + filename
# -- Go to the next file --
self.__current_index += 1
return filename
# -- Get file at--
def file_at(self, file_index, append_path=True):
# -- Check if it's in the range --
if file_index >= len(self.__list):
return None
# -- Get the filename --
filename = self.__list[file_index]
# -- Append with path if it's needed --
if append_path:
filename = self.__path + filename
# -- Go to the next file --
return filename
# -- Get file list --
def get_list(self):
return self.__list