forked from zhaoxuhui/ROS-Bag-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genTimeStamps.py
52 lines (42 loc) · 1.36 KB
/
genTimeStamps.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
# coding=utf-8
import os
import sys
def findAllFiles(root_dir, filter):
"""
在指定目录查找指定类型文件
:param root_dir: 查找目录
:param filter: 文件类型
:return: 路径、名称、文件全路径
"""
print("Finding files ends with \'" + filter + "\' ...")
separator = os.path.sep
paths = []
names = []
files = []
for parent, dirname, filenames in os.walk(root_dir):
for filename in filenames:
if filename.endswith(filter):
paths.append(parent + separator)
names.append(filename)
for i in range(paths.__len__()):
files.append(paths[i] + names[i])
print(names.__len__().__str__() + " files have been found.")
paths.sort()
names.sort()
files.sort()
return paths, names, files
if __name__ == "__main__":
img_dir = sys.argv[1]
save_path = img_dir + os.path.sep + "timestamps.txt"
if len(sys.argv) == 2:
img_type = ".jpg"
else:
img_type = sys.argv[2]
paths, names, files = findAllFiles(img_dir, img_type)
fout = open(save_path, "w")
for i in range(len(names)):
out_name = names[i].split(img_type)[0]
print(out_name)
fout.write(out_name + "\n")
fout.close()
print("Timestamp file has been saved at:" + save_path)