forked from GeorgeCiesinski/text-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglib.py
80 lines (51 loc) · 1.59 KB
/
glib.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
"""
George's Library
Contains non-class methods for this program.
"""
import os
def list_subdirectories(directory):
"""
Lists all subdirectories.
:param directory:
:return directory_list:
:rtype list:
"""
directory_list = list()
for root, dirs, files in os.walk(directory, topdown=False):
for name in dirs:
directory_list.append(os.path.join(root, name))
return directory_list
def list_files(directory):
"""
Lists all files and subdirectories in the directory. Returns list
:param directory:
:return file_list, file_dir_list:
:rtype list:
"""
file_list = list()
file_dir_list = list()
for root, dirs, files in os.walk(directory, topdown=False):
for name in files:
file_list.append(name)
file_dir_list.append(os.path.join(root, name))
return file_list, file_dir_list
def list_shortcuts(file_list):
"""
list_shortcuts creates a list of the raw shortcut strings the user would be typing in
:param file_list:
:return shortcut_list:
:rtype list:
"""
shortcut_list = list()
for f in file_list:
f = f.split(".")
shortcut_list.append(f[0])
return shortcut_list
def print_shortcuts(file_dir_list, shortcut_list):
for file_dir in file_dir_list:
index = file_dir_list.index(file_dir)
print(f"Shortcut: {shortcut_list[index]} - - - Directory: {file_dir}")
if __name__ == "__main__":
text_block_dir = 'Textblocks/'
file_list = list_files(text_block_dir)
shortcut_list = list_shortcuts(file_list)