-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_root_dir.py
44 lines (36 loc) · 1.54 KB
/
set_root_dir.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
import os
# Asks user for root directory information
def set_root_dir(root_dir):
root_dir.repo_name = input("Enter name of directory: ")
root_dir.root_path = input("Enter the root directory's path: ")
root_dir.dir_path = f"{root_dir.root_path}/{root_dir.repo_name}"
# Condition statement
everything_is_correct = False
while not everything_is_correct:
# Verify the root's path with the user
correct_root_path = input(
f'Is this the correct path for the directory: "{root_dir.dir_path}" \n[y/n]: '
).lower()
# If the user entered a valid response
if correct_root_path == "n" or correct_root_path == "y":
# If the root path is NOT correct
if correct_root_path == "n":
set_root_dir(root_dir)
# If the root path is correct
elif correct_root_path == "y":
# If the directory does not exist
if not os.path.isdir(root_dir.dir_path):
print(
f'"{root_dir.repo_name}" does not exist. Please double check the root directory name and path.'
)
set_root_dir(root_dir)
# If the directory exists
else:
print(
f'Great! Locating all subdirectories of "{root_dir.repo_name}"'
)
# Change condition
everything_is_correct = True
# For all invalid entries
else:
print("Not a valid response.")