forked from guangzhengli/ChatFiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.py
35 lines (20 loc) · 870 Bytes
/
file.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
from pathlib import Path
index_path = './documents'
index_file_dir = Path(index_path)
def get_index_name_from_file_name(file_name):
file_with_type = str(Path(file_name).relative_to(index_file_dir).name)
file_index_name = file_with_type.split('.')[0]
return get_index_name_with_json_extension(file_index_name)
def get_index_name_without_json_extension(index_name):
return index_name.replace(".json", "")
def get_index_name_with_json_extension(index_name):
return index_name + '.json'
def get_index_filepath(index_name):
return index_file_dir / index_name
def get_index_path():
return index_path
def check_index_file_exists(index_name):
return get_index_filepath(index_name).is_file()
def check_index_exists(file_name):
index_name = get_index_name_from_file_name(file_name)
return check_index_file_exists(index_name)