-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
58 lines (41 loc) · 1.31 KB
/
Copy pathutils.py
File metadata and controls
58 lines (41 loc) · 1.31 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
57
58
import os
import time
from pprint import pprint
def tic(): return time.time()
def toc(start):
W, H = os.get_terminal_size()
end = time.time()
msg = "TIME %.02f s" % (end - start)
print(msg.center(W, "_"))
return end
def logger(verbose = True):
""" Logger initiation """
W, H = os.get_terminal_size()
def log(*arg):
if verbose:
print("_" * W)
msgs = [*arg]
for msg in msgs:
print(str(msg).upper().rjust(W, "|"))
print("‾" * W)
return log
def file_selector_corrected(dir_path = None):
""" File selector with numbered files, ignores folders """
if not dir_path:
current_dir = os.getcwd()
elif not os.path.exists(dir_path):
print("Invalid dir name")
return dir_path
else:
current_dir = os.chdir(dir_path)
file_list = [file for file in os.listdir(current_dir) if os.path.isfile(file)]
if not file_list:
print("Empty directory")
for i, f in enumerate(file_list):
print(str(i).rjust(3), "->", f)
while True:
try:
user_input = int(input("Which file do you want? "))
return file_list[user_input]
except (ValueError, IndexError):
print("Invalid input. Please try again.")