-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathFile Manager.py
More file actions
490 lines (358 loc) · 17 KB
/
File Manager.py
File metadata and controls
490 lines (358 loc) · 17 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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
'''
This is a python based file manager system
for Microsoft Windows made by Aman Binjola
as a personal project.
28-November-2019
https://github.com/binjolaaman10/python-file-manager
'''
#! python3
import sys
import os
import shutil
import send2trash
print('Welcome to the python-file-manager\n')
# Stores every drive connected on PC in a list.
drives = [chr(x) + ':' for x in range(65, 90) if os.path.exists(chr(x) + ':')]
# Lists each folder and file present in the current working directory
def listDirectories():
listdir = os.listdir(os.getcwd())
for x in listdir:
print(x)
while True:
print("1.Open files/folders \n2.Rename \n3.Move and Paste \n4.Copy and Paste \n5.Delete\n")
result = input("Choose one of the following: ")
if result == '1':
# Home Screen
print('\nQuick Acess:\n1. Documents\n2. Videos\n3. Pictures\n4. Downloads\n')
print('Drives: ')
for x in range(len(drives)):
print(str(5 + x) + '. ' + drives[x])
while True:
inp = input("\nEnter your Choice: ")
if inp == '1':
path = 'C:\\Users\\$USERNAME\\Documents'
os.chdir(os.path.expandvars(path))
break
elif inp == '2':
path = 'C:\\Users\\$USERNAME\\Videos'
os.chdir(os.path.expandvars(path))
break
elif inp == '3':
path = 'C:\\Users\\$USERNAME\\Pictures'
os.chdir(os.path.expandvars(path))
break
elif inp == '4':
path = 'C:\\Users\\$USERNAME\\Downloads'
os.chdir(os.path.expandvars(path))
break
elif inp in drives:
os.chdir(inp + '\\')
break
else:
print('Error\nEnter a correct input / drive name.\n')
while True:
listDirectories()
print('\n\nType "exitManager" to exit from file manager.')
print('Type "backManager" to go up one directory.')
res = input('\nChoose a file/folder: ')
print('\n')
if res in os.listdir(os.getcwd()):
if os.path.isfile(res):
os.system('"' + res + '"')
else:
os.chdir(res)
elif res == 'exitManager': # Exit command to exit from loop
sys.exit(0)
elif res == 'backManager': # Back command to go up one directory
os.chdir('..')
else:
print('No file/folder exist of this name.')
if result == '2':
print("You chose to rename")
print('Drives: ')
for x in range(len(drives)):
print(str(1 + x) + '. ' + drives[x])
while True:
inp = input("\nEnter your Choice: ")
if inp in drives:
os.chdir(inp + '\\')
break
else:
print('Error\nEnter a correct drive name.\n')
while True:
listDirectories()
print('\n\nType "exitManager" to exit from file manager.')
print('Type "backManager" to go up one directory.')
print('Type "renameManager" to rename this directory')
res = input('\nChoose a file to rename: ')
print('\n')
if res in os.listdir(os.getcwd()):
if os.path.isfile(res):
new_name = input("Enter a new name: ")
ogDir = res
newDir = os.getcwd() + '\\' + new_name
shutil.move(ogDir, newDir)
else:
os.chdir(res)
elif res == 'exitManager': # Exit command to exit from loop
sys.exit(0)
elif res == 'backManager': # Back command to go up one directory
os.chdir('..')
elif res == 'renameManager': # Rename command to delete one directory
new_name = input("Enter a new name: ")
ogDir = os.getcwd()
os.chdir('..')
newDir = os.getcwd() + '\\' + new_name
shutil.move(ogDir, newDir)
else:
print('No file/folder exist of this name.')
if result == '3':
print("You chose to move")
print('Drives: ')
for x in range(len(drives)):
print(str(1 + x) + '. ' + drives[x])
while True:
inp = input("\nEnter your Choice: ")
if inp in drives:
os.chdir(inp + '\\')
break
else:
print('Error\nEnter a correct drive name.\n')
while True:
listDirectories()
print('\n\nType "exitManager" to exit from file manager.')
print('Type "backManager" to go up one directory.')
print('Type "cutManager" to move this directory')
res = input('\nChoose a file to move: ')
print('\n')
if res in os.listdir(os.getcwd()):
if os.path.isfile(res):
og_path = os.getcwd() + "\\" + res
print("\nMove " + res + " to a desired location.")
while True:
for x in range(len(drives)):
print(str(1 + x) + '. ' + drives[x])
inp2 = input("\nEnter your Choice: ")
if inp2 in drives:
os.chdir(inp2 + '\\')
break
else:
print('Error\nEnter a correct drive name.\n')
while True:
listDirectories()
print('Type "pasteManager" to paste this file in current directory')
res2 = input('\nChoose a file to move: ')
print('\n')
if res2 in os.listdir(os.getcwd()):
if os.path.isfile(res):
print("You can't choose a file.\nPlease choose a folder.")
else:
os.chdir(res2)
elif res2 == 'pasteManager':
shutil.move(og_path, os.getcwd())
break
else:
os.chdir(res)
elif res == 'exitManager': # Exit command to exit from loop
sys.exit(0)
elif res == 'backManager': # Back command to go up one directory
os.chdir('..')
elif res == 'cutManager':
og_path = os.getcwd()
print("Moving the current directory")
while True:
for x in range(len(drives)):
print(str(1 + x) + '. ' + drives[x])
inp2 = input("\nEnter your Choice: ")
if inp2 in drives:
os.chdir(inp2 + '\\')
break
else:
print('Error\nEnter a correct drive name.\n')
while True:
listDirectories()
print('\nType "pasteManager" to paste this folder in current directory')
res2 = input('\nChoose a folder to open: ')
print('\n')
if res2 in os.listdir(os.getcwd()):
if os.path.isfile(res):
print("You can't choose a file.\nPlease choose a folder.")
else:
os.chdir(res2)
elif res2 == 'pasteManager':
shutil.move(og_path, os.getcwd())
break
else:
print('No file/folder exist of this name.')
if result == '4':
print("You chose to copy")
print('Drives: ')
for x in range(len(drives)):
print(str(1 + x) + '. ' + drives[x])
while True:
inp = input("\nEnter your Choice: ")
if inp in drives:
os.chdir(inp + '\\')
break
else:
print('Error\nEnter a correct drive name.\n')
while True:
listDirectories()
print('\n\nType "exitManager" to exit from file manager.')
print('Type "backManager" to go up one directory.')
print('Type "copyManager" to copy this directory')
res = input('\nChoose a file to copy: ')
print('\n')
if res in os.listdir(os.getcwd()):
if os.path.isfile(res):
og_path = os.getcwd() + "\\" + res
print("Move " + res + " to a desired location.")
while True:
for x in range(len(drives)):
print(str(1 + x) + '. ' + drives[x])
inp2 = input("\nEnter your Choice: ")
if inp2 in drives:
os.chdir(inp2 + '\\')
break
else:
print('Error\nEnter a correct drive name.\n')
while True:
listDirectories()
print('Type "pasteManager" to copy this file in current directory')
res2 = input('\nChoose a file to move: ')
print('\n')
if res2 in os.listdir(os.getcwd()):
if os.path.isfile(res):
print("You can't choose a file.\nPlease choose a folder.")
else:
os.chdir(res2)
elif res2 == 'pasteManager':
shutil.copy(og_path, os.getcwd())
break
else:
os.chdir(res)
elif res == 'exitManager': # Exit command to exit from loop
sys.exit(0)
elif res == 'backManager': # Back command to go up one directory
os.chdir('..')
elif res == 'copyManager':
og_path = os.getcwd()
print("Copying the current directory")
while True:
for x in range(len(drives)):
print(str(1 + x) + '. ' + drives[x])
inp2 = input("\nEnter your Choice: ")
if inp2 in drives:
os.chdir(inp2 + '\\')
break
else:
print('Error\nEnter a correct drive name.\n')
while True:
listDirectories()
print('\nType "pasteManager" to copy this file in current directory')
res2 = input('\nChoose a folder to open: ')
print('\n')
if res2 in os.listdir(os.getcwd()):
if os.path.isfile(res):
print("You can't choose a file.\nPlease choose a folder.")
else:
os.chdir(res2)
elif res2 == 'pasteManager':
print(og_path)
folder_name = og_path.split('\\')[-1]
folder_directory = os.getcwd() + '\\' + folder_name
shutil.copytree(og_path, folder_directory)
break
else:
print('No file/folder exist of this name.')
if result == '5':
while True:
# Options to delete files/folders to permanently or otherwise
print('\n1. Permanently \n2. Recycle Bin')
query = input('Would you like to permanently delete or send to Recycle Bin?: ')
if query == '1':
print('You chose to permanently delete files/folders.\n')
print('Drives: ')
for x in range(len(drives)):
print(str(1 + x) + '. ' + drives[x])
while True:
inp = input("\nEnter your Choice: ")
if inp in drives:
os.chdir(inp + '\\')
break
else:
print('Error\nEnter a correct drive name.\n')
while True:
listDirectories()
print('\n\nType "exitManager" to exit from file manager.')
print('Type "backManager" to go up one directory.')
print('Type "deleteManager" to permanently delete this directory')
res = input('\nChoose a file to delete: ')
print('\n')
if res in os.listdir(os.getcwd()):
if os.path.isfile(res):
# Warning to prevent unnecessary deletion
print('Are you sure you want to permanently delete this file? (YES/NO)')
ans = input('Yes or No: ')
if ans.lower() == 'yes' or 'y':
os.unlink(res)
else:
os.chdir(res)
elif res == 'exitManager': # Exit command to exit from loop
sys.exit(0)
elif res == 'backManager': # Back command to go up one directory
os.chdir('..')
elif res == 'deleteManager': # Delete command to delete one directory
# Warning to prevent unnecessary deletion
print('Are you sure you want to permanently delete this folder? (YES/NO)')
ans = input('Yes or No: ')
if ans.lower() == 'yes' or 'y':
path = os.getcwd()
os.chdir('..')
shutil.rmtree(path)
else:
print('No file/folder exist of this name.')
elif query == '2':
print('You chose to temporarily delete files/folders.')
print('Drives: ')
for x in range(len(drives)):
print(str(1 + x) + '. ' + drives[x])
while True:
inp = input("\nEnter your Choice: ")
if inp in drives:
os.chdir(inp + '\\')
break
else:
print('Error\nEnter a correct drive name.\n')
while True:
listDirectories()
print('\n\nType "exitManager" to exit from file manager.')
print('Type "backManager" to go up one directory.')
print('Type "deleteManager" to send this directory to recycle bin')
res = input('\nChoose a file to delete: ')
print('\n')
if res in os.listdir(os.getcwd()):
if os.path.isfile(res):
# Warning to prevent unnecessary deletion
print('Are you sure you want to send this folder to recycle bin? (YES/NO)')
ans = input('Yes or No: ')
if ans.lower() == 'yes' or 'y':
send2trash.send2trash(res)
else:
os.chdir(res)
elif res == 'exitManager': # Exit command to exit from loop
sys.exit(0)
elif res == 'backManager': # Back command to go up one directory
os.chdir('..')
elif res == 'deleteManager': # Delete command to delete one directory
# Warning to prevent unnecessary deletion
print('Are you sure you want to send this folder to recycle bin? (YES/NO)')
ans = input('Yes or No: ')
if ans.lower() == 'yes' or 'y':
path = os.getcwd()
os.chdir('..')
send2trash.send2trash(path)
else:
print('No file/folder exist of this name.')
else:
print('You chose wrong number')