-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpath_saver.py
More file actions
54 lines (41 loc) · 1.36 KB
/
path_saver.py
File metadata and controls
54 lines (41 loc) · 1.36 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
import os.path
DIRECTORY = os.path.expanduser("~/.wry_asset_ripper_ui")
FILE = "last_path.txt"
EXPORT_FILE = "last_export_path.txt"
def save_last_path(path: str):
try:
if not os.path.isdir(DIRECTORY):
os.mkdir(DIRECTORY)
with open(os.path.join(DIRECTORY, FILE), "w+") as f:
f.write(path)
except Exception:
return
def get_last_path():
try:
if not os.path.exists(os.path.join(DIRECTORY, FILE)):
return "."
with open(os.path.join(DIRECTORY, FILE), "r+") as f:
return f.read().strip()
except Exception:
return "."
def save_last_export_path(path: str):
try:
if not os.path.isdir(DIRECTORY):
os.mkdir(DIRECTORY)
with open(os.path.join(DIRECTORY, EXPORT_FILE), "w+") as f:
f.write(path)
except Exception:
return
def get_last_export_path():
try:
if not os.path.exists(os.path.join(DIRECTORY, FILE)):
return "."
with open(os.path.join(DIRECTORY, EXPORT_FILE), "r+") as f:
return f.read().strip()
except Exception:
return "."
def get_file_dir(file: str):
file = file.replace("\\", "/")
return "/".join(file.split("/")[:-1])
if __name__ == "__main__":
print(get_file_dir("C:/Users\\test/file.ab"))