-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirSearch.py
More file actions
73 lines (64 loc) · 1.85 KB
/
Copy pathdirSearch.py
File metadata and controls
73 lines (64 loc) · 1.85 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
def searchDir(targetDir, name):
result = []
for root, dirs, files in os.walk(targetDir, topdown=True):
if name in dirs:
result = os.path.join(root, name)
break
return result
def rePrompt():
yes = 'y'
no = 'n'
searchAgain = 0
print()
print('Would you like to search again? Please enter \'y\' or \'n\'')
searchPrompt = input()
for i in range(10):
if searchPrompt == yes:
searchAgain = 1
elif searchPrompt == no:
break
elif searchPrompt != no & i < 5:
print('Please enter only \'y\' or \'n\'')
continue
elif i == 10:
print('Too many invalid inputs.')
print('Exiting Program')
quit()
return searchAgain
def searchPrompt():
cwDir = os.getcwd()
yes = 'y'
no = 'n'
print('This will search the current working directory and its subdirectories.')
print(cwDir)
print()
print('Would you like to search a different directory? y or n')
searchDif = input()
if searchDif == yes:
print('Please enter the directory you would like to search.')
print('Be sure to use a double slash \\\\ instead of a single slash \\')
newDir = input()
newDirNice = os.path.abspath(newDir)
os.chdir(newDirNice)
cwDir = os.getcwd()
print('Now searching in ' + cwDir)
print()
print('Please enter target directory name:')
search4 = input()
return search4
while (1):
try:
wantItem = searchPrompt()
cwDir = os.getcwd()
searchResult = searchDir(cwDir, wantItem)
print(searchResult)
reRun = rePrompt()
if reRun == 1:
continue
else:
print('Exiting Program')
break
except:
print('Unexpected Error')
break