-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.py
53 lines (49 loc) · 2.46 KB
/
validate.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
from os.path import isfile, isdir
def validate_file(filename):
try:
if isfile(filename):
return filename
else:
print("\"" + filename + "\" does not exist in the current directory.")
response = raw_input("Would you like to specify a search path?(Y/N)? ")
while response.lower() != 'y' and response.lower() != 'n':
response = raw_input("Would you like to specify a search path?(Y/N)? ")
while response == 'Y' or response == 'y':
path = raw_input("Enter the path: ")
print(path)
if isdir(path):
if isfile(path + '\\' + filename):
return path + '\\' + filename
else:
msg = "\"" + filename + "\" does not exist in the specified path"
msg += "\nWould you like to specify the search path again?(Y/N)? "
response = raw_input(msg)
while response.lower() != 'y' and response.lower() != 'n':
response = raw_input("Would you like to specify the path again?(Y/N)? ")
elif isfile(path):
return path
else:
msg = "\"" + path + "\" is not a valid directory \nWould you like to specify the path again?(Y/N)? "
response = raw_input(msg)
while response.lower() != 'y' and response.lower() != 'n':
response = raw_input("Would you like to specify the path again?(Y/N)? ")
if response == 'N' or response == 'n':
return -1
except Exception as e:
print('Exception thrown in validateFile() ' + str(e))
def validate_dir(directory_name):
if isdir(directory_name):
return directory_name
else:
print("\"" + directory_name + "\" does not exist in the current working directory")
ch = raw_input("Would you like to specify a search path?(Y/N)? ").upper()
while True:
if ch == "Y":
path = raw_input("Enter the path: ")
if isdir(path):
return path
else:
print("\"" + path + "\" is not a valid directory")
elif ch == 'N':
return -1
ch = raw_input("Would you like to specify the path again?(Y/N)? ").upper()