-
Notifications
You must be signed in to change notification settings - Fork 0
/
directoryExplorer.py
48 lines (39 loc) · 1.5 KB
/
directoryExplorer.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
#! Python3
# directoryExplorer.py - Navigates the directory.
# I wrote this so I don't have to keep writing this on programs working
# with the operating system.
import os
# Doesn't work as intented when imported into another program. Fix dis.
def directoryExplorer(current_directory):
#move_backwards = current_directory.split(os.sep)
move_forwards = next(os.walk(current_directory))[1]
print('\nThis is your current directory: ' + current_directory)
print('These are the folders available in your current directory: ' + str(os.path.basename(current_directory)))
print(move_forwards)
print('where do you want to go?\n')
go_to = input(""" Options...
1. Pick a directory to move forward.
2. Type BACK to move back a directory.
3. Type STAY to stay in directory,
4. Type EXIT to escape program.\n > """)
if go_to.lower() == 'back': #Move Back
print('Moving backwards to ' + os.path.split(os.getcwd())[0])
new_path = os.path.split(os.getcwd())[0]
print(new_path)
os.chdir(new_path)
directoryExplorer(new_path)
elif go_to in move_forwards: # Move Forwards
print('moving forwards to ' + str(go_to))
new_path = os.getcwd() + '/'+ go_to
os.chdir(new_path)
directoryExplorer(new_path)
elif go_to.lower() == 'stay': # Stay
print('Staying in this directory.')
elif go_to.lower() == 'exit':
exit()
else: # Exit program
print('That is not an option')
directoryExplorer(current_directory)
if __name__ == '__main__':
current_directory = os.getcwd()
directoryExplorer(current_directory)