-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos_functions.py
52 lines (42 loc) · 1.45 KB
/
os_functions.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
import os
def searchFolder(search_path: str):
numPaths = 0
print("Update: Searching for PDFs")
paths = []
for root, _, files in os.walk(search_path):
for file in files:
if file.endswith(".pdf") and not file.startswith("-"):
numPaths += 1
paths.append(os.path.join(root, file))
print("Update: Found " + str(numPaths) + " paths")
return paths
def checkInputPathExists(file: str):
try:
path = os.path.exists(file)
if path:
print("Update: Input path exists")
return True
else:
print("Error: Input path does not exist")
return False
except PermissionError:
print("Permission error: Unable to access the file.")
return False
except OSError as e:
print("Error: Cannot access input folder: " + e)
return False
except ValueError as e:
print("Error: Cannot access input folder: " + e)
return False
def checkOutputFileType(file: str, inputPath: str):
if not file:
return getLastInputPathParameter(inputPath)
elif not file.endswith(".ris"):
return file.split(".")[0] + ".ris"
else:
return file
# TODO Update readme to reflect where output file will go
def getLastInputPathParameter(inputPath: str):
folderName = os.path.basename(os.path.normpath(inputPath))
fileName = folderName + ".ris"
return os.path.join(inputPath, fileName)