-
Notifications
You must be signed in to change notification settings - Fork 0
/
xplorer.py
133 lines (106 loc) · 3.31 KB
/
xplorer.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
from termcolor import colored
os.system('clear')
path = input(colored('Enter path: ', 'green'))
# show all files in folder
def show():
files = os.listdir(path)
for ind, file in enumerate(files):
print(ind, file)
# show help menu
def option():
print('\nshow ==> to show items in folder')
# print('help ==> to show this options')
print('cls ==> to clear the terminal window')
print('format ==> to change the format of files')
print('rename ==> to rename all files in folder')
print('quit ==> to quit the script')
print('dir ==> to show the current working directory')
print('num ==> to show the number of items in the folder')
# to rename all files in directory
def rename():
new_name = input('Enter new name: ')
for files in os.listdir(os.chdir(path)):
os.renames(files, new_name)
for new_name in os.listdir(os.getcwd()):
print(new_name)
def newpath():
newDir = input("Enter new path: ")
try:
if os.path.exists(newDir):
os.chdir(newDir) ## TODO
path = newDir
except:
print('Invalid path provided...')
# to change files format
def reformat_files():
ext = input('Enter format to change to: ')
for files in os.listdir(os.chdir(path)):
os.move(files, files + ext)
done = os.listdir(os.getcwd())
for fil in done:
print(fil)
# quit command to quit the script
def quit_scr():
print('Goodbye, catch you next time.')
# pyautogui.hotkey('ctrl', 'c')
os.system('clear')
exit(0)
# cls command to clear the text off the terminal screen
def cls():
os.system('clear')
# folder command to show the current working directory
def folder():
print(colored('You are currently in: ' + path, 'green'))
# to show the total number of files in the folder
def num_files():
files = os.listdir(path)
count = len(files)
if count == 1:
print(colored('There is ' + str(count) + ' item in this folder', 'yellow'))
else:
print(colored('There are ' + str(count) + ' items in this folder.', 'yellow'))
# the commander
try:
def cmd():
option()
command = input(colored('command > ', 'green'))
# if command == 'help':
# os.system('clear')
# option()
if command == 'change':
os.system('clear')
newpath()
if command == 'quit':
while command:
quit_scr()
elif command == 'show':
os.system('clear')
show()
elif command == 'format':
os.system('clear')
reformat_files()
elif command == 'cls':
cls()
elif command == 'rename':
os.system('clear')
rename()
elif command == 'dir':
os.system('clear')
folder()
elif command == 'num':
os.system('clear')
num_files()
else:
os.system('clear')
print('Invalid command, type help for more info.')
except:
newpath()
def runner():
while path:
if os.path.exists(path):
cmd()
else:
print('Invalid path')
exit(1)
runner()