-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfile_select_gui.py
More file actions
executable file
·56 lines (41 loc) · 1.62 KB
/
file_select_gui.py
File metadata and controls
executable file
·56 lines (41 loc) · 1.62 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
55
56
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 12 15:10:28 2017
Small functions to select file or directory paths via a GUI
@author: Robin Amsters
@email: robin.amsters@gmail.com
"""
import numpy as np
import os
from fnmatch import fnmatch
from Tkinter import Tk
from tkFileDialog import askopenfile , askdirectory
def get_file_path(msg):
# Selecting file trough GUI
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filePath = askopenfile(title = msg) # show an "Open" dialog box and return the path to the selected file
return filePath
def get_directory_path(msg):
# Selecting directory trough GUI
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filePath = askdirectory(title = msg) # show an "Open" dialog box and return the path
return filePath
def get_all_files_directory(directory, pattern):
"""
Function that returns all the path to all files in a directory
and its subdirectories that end in a certain pattern.
"""
root = directory
allFiles = np.array([])
for path, subdirs, files in os.walk(root):
for name in files:
if fnmatch(name, pattern):
allFiles = np.append(allFiles, os.path.join(path, name))
return allFiles
def get_folder_names(directory):
folders = os.walk(directory).next()[1]
return folders
if __name__=='__main__':
# list all rosbag files
directory = get_directory_path('select directory')
print(get_all_files_directory(directory, '*.bag'))