-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_manager.py
271 lines (248 loc) · 10.2 KB
/
file_manager.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#ٌWriteD BY ME!
from subprocess import check_output
from string import ascii_uppercase
from os import system, walk, path
from colorama import Fore
CHANGED = ''
def find_drives():
system_drives = []
cmd = str(check_output("net share", shell=True))
for i in ascii_uppercase:
if i+':' in cmd:
system_drives.append(i)
return system_drives
def search(name, root) :
result = []
for root, dirs, files in walk(root) :
for d in dirs :
if name in d :
result.append(path.join(root, d))
for f in files :
if name in f :
result.append(path.join(root, f))
return result
def show_list(root) :
system('cls')
global CHANGED
for root, dirs, files in walk(root):
print(Fore.CYAN+' (YoU ArE HerE)==> '+root)
print(Fore.LIGHTGREEN_EX+'\n DireS : \n'+Fore.WHITE)
for i in range(len(dirs)):
if dirs[i] == CHANGED :
print(Fore.LIGHTMAGENTA_EX+' >>'+dirs[i]+Fore.WHITE)
CHANGED = ''
else :
print(' >>'+dirs[i])
print(Fore.LIGHTGREEN_EX+'\n FileS : \n'+Fore.WHITE)
for j in range(len(files)):
if files[j] == CHANGED :
print(Fore.LIGHTMAGENTA_EX+' >>'+files[j]+Fore.WHITE)
CHANGED = ''
else :
print(' >>'+files[j])
return dirs, files
system('cls')
print(Fore.CYAN+'''\n
███╗ ███╗ █████╗ ███╗ ███╗ █████╗ ██████╗ ██████╗ ███████╗
████╗ ████║██╔══██╗████╗ ████║██╔══██╗██╔══██╗██╔═══██╗██╔════╝ MMD FilE ManageR
██╔████╔██║███████║██╔████╔██║███████║██║ ██║██║ ██║█████╗
██║╚██╔╝██║██╔══██║██║╚██╔╝██║██╔══██║██║ ██║██║ ██║██╔══╝ VersioN 1.85-WindowS
██║ ╚═╝ ██║██║ ██║██║ ╚═╝ ██║██║ ██║██████╔╝╚██████╔╝██║
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═╝
\n''')
characters = ['/', '\\', ':', '*', '<', '>', '?', '"', '|']
while True :
root = input(Fore.BLUE+'\n SelecT DrivE '+Fore.GREEN+str(find_drives())+Fore.GREEN+'==>'+Fore.WHITE).upper()
if root in find_drives():
break
else :
print(Fore.RED+'\n EnteR A CorrecT DrivE ')
root += ':\\'
dirs, files = show_list(root)
copy = ''
cut = ''
while True :
select = input(Fore.YELLOW+'\n SelecT DirectorY, FilE OR CommanD ==>'+Fore.WHITE)
if select == '/help' :
print(Fore.CYAN+'''
╔══════════════════════════════════════════════════╗
| /back : ReturN TO PreviuS DirectorY |
|
| /root : GO TO ThE CurrenT DrivE RooT |
|
| /change : ChangE CurrenT DrivE |
|
| /rename : RenamE A FoldeR/FilE |
|
| /new : CreatE A NeW FoldeR/FilE |
|
| /delete : DeletE A FoldeR/FilE |
|
| /copy : CopY FilE(s) TO ClipboarD |
|
| /cut : CuT A FoldeR/FilE TO ClipboarD |
|
| /paste : PstE A FoldeR/FilE FroM ClipboarD |
|
| /clipboard: ShowS WhatS IN ClipboarD |
|
| /search : SearcH A FoldeR/FilE |
|
| /tree : ShoW TreE OF FolderS |
|
| /refresh : ReloaD DirectorY LisT |
|
| /exit : ClosE FilE ManageR |
╚══════════════════════════════════════════════════╝''')
elif select == '/back' :
if root.rfind('\\') != -1 :
slash = root.rfind('\\')
root = root[:slash]
else :
root += '\\'
if root.find('\\') == -1 :
root += '\\'
dirs, files = show_list(root)
elif select == '/root' :
slash = root.find('\\')
root = root[:slash+1]
dirs, files = show_list(root)
elif select == '/change' :
system('cls')
while True :
root = input(Fore.BLUE+'\n SelecT DrivE '+Fore.GREEN+str(find_drives())+Fore.GREEN+'==> '+Fore.WHITE).upper()
if root in find_drives() :
break
else :
print(Fore.RED+'\n EnteR A CorrecT DrivE ')
root += ':\\'
dirs, files = show_list(root)
elif select == '/rename' :
found = False
name = input(Fore.BLUE+'\n SelecT DirectorY OR FilE TO RenamE ==>'+Fore.WHITE)
if name in dirs or name in files :
change = input(Fore.MAGENTA+'\n EnteR NeW NamE ('+Fore.RED+'WithouT /\*:><?"|'+Fore.MAGENTA+') ==>'+Fore.WHITE)
for char in characters :
if char in change :
found = True
if not found :
system('ren \"'+root+'\\'+name+'\" '+change)
CHANGED = change
dirs, files = show_list(root)
else :
print(Fore.RED+'\n FoldeR/FilE NamE CanT ContaiN ThiS CharacterS '+Fore.BLUE+' /\*:><?"| ')
else :
print(Fore.RED+'\n NO SucH A FilE OR DirectorY!\n')
elif select == '/new' :
found = False
which = input(Fore.BLUE+'\n CreatE A NeW FoldeR OR FilE ? O/I :'+Fore.WHITE).upper()
new = input(Fore.MAGENTA+'\n EnteR NamE ('+Fore.RED+'WithouT /\*:><?"|'+Fore.MAGENTA+') ==>'+Fore.WHITE)
for char in characters :
if char in new :
found = True
if not found :
if which == 'O' :
if new not in files and new not in dirs :
system('md '+root+'\\'+new)
CHANGED = new
dirs, files = show_list(root)
else :
print(Fore.RED+'\n NamE '+new+' IS AlredY ExisT!')
if which == 'I' :
if new not in files and new not in dirs :
open(root+'\\'+new , 'w').close()
CHANGED = new
dirs, files = show_list(root)
else :
print(Fore.RED+'\n NamE '+new+' IS AlredY ExisT!')
else :
print(Fore.RED+'\n FoldeR/FilE NamE CanT ContaiN ThiS CharacterS /\*:><?"| ')
elif select == '/delete' :
delete = input(Fore.BLUE+'\n SelecT DirectorY OR FilE TO DeletE ==>'+Fore.WHITE)
if delete in files :
sure = input(Fore.MAGENTA+'\n ArE YoU SurE YoU WanT TO DeletE '+delete+' ? Y/N :'+Fore.WHITE).upper()
if sure == 'Y' :
system('del \"'+root+'\\'+delete+'\"')
dirs, files = show_list(root)
else :
print(Fore.RED+'\n CanceleD!')
elif delete in dirs :
sure = input(Fore.MAGENTA+'\n ArE YoU SurE YoU WanT TO DeletE '+delete+' ? Y/N :'+Fore.WHITE).upper()
if sure == 'Y' :
system('rd /s /q \"'+root+'\\'+delete+'\"')
dirs, files = show_list(root)
else :
print(Fore.RED+'\n CanceleD!')
else :
print(Fore.RED+'\n NO SucH A FilE OR DirectorY!\n')
elif select == '/copy' :
need = ''
copy = input(Fore.BLUE+'\n SelecT DirectorY OR FilE TO CopY ==>'+Fore.WHITE)
if copy in dirs or copy in files :
chang = copy
if copy in dirs :
need = '\\'+copy
copy = root+'\\'+copy
print(Fore.GREEN+'\n SaveD IN ClipboarD!')
cut = ''
else :
print(Fore.RED+'\n NO SucH A FilE OR DirectorY!\n')
elif select == '/cut' :
cut = input(Fore.BLUE+'\n SelecT DirectorY OR FilE TO CuT ==>'+Fore.WHITE)
if cut in dirs or cut in files :
chang = cut
cut = root+'\\'+cut
print(Fore.GREEN+'\n SaveD IN ClipboarD!')
copy = ''
else :
print(Fore.RED+'\n NO SucH A FilE OR DirectorY!\n')
elif select == '/paste' :
if copy != '' :
if need :
system('md \"'+root+need+'\"')
system('copy \"'+copy+'\" \"'+root+need+'\"')
need = ''
else :
system('copy \"'+copy+'\" \"'+root+'\"')
copy = ''
CHANGED = chang
dirs, files = show_list(root)
elif cut != '' :
system('move \"'+cut+'\" \"'+root+'\"')
cut = ''
CHANGED = chang
dirs, files = show_list(root)
else :
print(Fore.RED+'\n ClipboarD IS EmptY!\n')
elif select == '/clipboard' :
if copy :
print(Fore.GREEN+'\n'+copy)
elif cut :
print(Fore.GREEN+'\n'+cut)
else :
print(Fore.RED+'\nClipboarD IS EmptY!')
elif select == '/search' :
name = input(Fore.BLUE+'\n EnteR NamE TO SearcH ==>'+Fore.WHITE)
list = search(name, root)
if list :
for res in list :
res = res.replace(root, '')
print(Fore.GREEN+res)
else :
print(Fore.RED+'\n NoT FounD!')
elif select == '/tree' :
print(Fore.MAGENTA)
system('tree \"'+root+'\"')
elif select == '/refresh' :
dirs, files = show_list(root)
elif select in dirs :
if root[-1] != '\\' :
root += '\\'
root += select
dirs, files = show_list(root)
elif select in files :
system('\"'+root+'\\'+select+'\"\n')
elif select == '/exit' :
exit()
else :
print(Fore.RED+'\n NO SucH A FilE OR DirectorY! NeeD "/help"?\n')