This repository has been archived by the owner on Nov 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFile-Manager.py
346 lines (265 loc) · 9.94 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
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
# Coding: utf-8
# python 3.8
from colorama import init, Fore, Back, Style
from send2trash import send2trash
from PIL import Image
import os
import os.path
import shutil
init()
# This function lists all files and directories.
def All_info(thispath):
Fpath = os.getcwd()
files = os.listdir()
print(Fore.LIGHTMAGENTA_EX)
print(f'{thispath} {Fpath}')
i = len(files)
for file in range(i):
if os.path.isdir(files[file]) == True:
print(files[file])
print('')
for file in range(i):
if os.path.isfile(files[file]) == True:
print(files[file])
# This function lists all directories.
def All_dir(thispath):
Fpath = os.getcwd()
files = os.listdir()
print(Fore.LIGHTMAGENTA_EX)
print(f'{thispath} {Fpath}')
i = len(files)
for file in range(i):
if os.path.isdir(files[file]) == True:
print(files[file])
# This function lists all files.
def All_files(thispath):
Fpath = os.getcwd()
files = os.listdir()
print(Fore.LIGHTMAGENTA_EX)
print(f'{thispath} {Fpath}')
i = len(files)
for file in range(i):
if os.path.isfile(files[file]) == True:
print(files[file])
# This function allows switching between directories.
def Jump(thispath, Jump_func_text, Directory_text):
print(Fore.LIGHTYELLOW_EX)
Jump_func = int(input(Jump_func_text))
if Jump_func == 1:
os.chdir('..')
Fpath = os.getcwd()
print(Fore.LIGHTMAGENTA_EX)
print(f'{thispath} {Fpath}')
if Jump_func == 2:
All_dir(thispath)
print(Fore.LIGHTGREEN_EX)
Directory = input(Directory_text)
os.chdir(Directory)
Fpath = os.getcwd()
print(Fore.LIGHTMAGENTA_EX)
print(f'{thispath} {Fpath}')
# Language selection.
print(Fore.LIGHTYELLOW_EX)
lang = int(input('Choose Language:\n1)English\n2)Russian Language\n'))
# English
if lang == 1:
from Lang_en import *
# Russian language
elif lang == 2:
from Lang_ru import *
# Error notification
else:
print(Fore.LIGHTRED_EX)
print('Error: This language does not exist.')
start = True
while start == True:
print(Fore.LIGHTGREEN_EX)
function = int(input(function_text))
try:
# The part that is responsible for outputting information about what files and directories are in this directory.
if function == 1:
All_info(thispath)
# This part is responsible for switching between directories.
elif function == 2:
Jump(thispath, Jump_func_text, Directory_text)
# The part that is responsible for copying.
# Selecting a function in copying.
elif function == 3:
print(Fore.LIGHTYELLOW_EX)
Copy_func = int(input(Copy_func_text))
# The part that is responsible for copying files.
if Copy_func == 1:
All_files(thispath)
print(Fore.LIGHTCYAN_EX)
file = input(file_text)
path = os.getcwd()
CaMO = 'n'
while CaMO == 'n':
Jump(thispath, Jump_func_text, Directory_text)
print(Fore.LIGHTGREEN_EX)
CaMO = input(CaMO_text)
CaMO = CaMO.lower()
path_to = os.getcwd()
shutil.copy(f'{path}\\{file}', f'{path_to}\\{file}')
# The part that is responsible for copying directories.
elif Copy_func == 2:
All_dir(thispath)
print(Fore.LIGHTCYAN_EX)
file = input(Directory_text)
path = os.getcwd()
CaMO = 'n'
while CaMO == 'n':
Jump(thispath, Jump_func_text, Directory_text)
print(Fore.LIGHTGREEN_EX)
CaMO = input(CaMO_text)
CaMO = CaMO.lower()
path_to = os.getcwd()
shutil.copytree(f'{path}\\{file}', f'{path_to}\\{file}')
# Error notification.
else:
print(Fore.LIGHTRED_EX)
print('Error: This function is missing.')
# This part is responsible for moving files and directories.
# Selecting a function in moving.
elif function == 4:
print(Fore.LIGHTYELLOW_EX)
Move_func = int(input(Move_func_text))
# This part is responsible for moving files.
if Move_func == 1:
All_files(thispath)
print(Fore.LIGHTCYAN_EX)
file = input(file_text)
path = os.getcwd()
CaMO = 'n'
while CaMO == 'n':
Jump(thispath, Jump_func_text, Directory_text)
print(Fore.LIGHTGREEN_EX)
CaMO = input(CaMO_text2)
CaMO = CaMO.lower()
path_to = os.getcwd()
shutil.move(f'{path}\\{file}', f'{path_to}\\{file}')
# This part is responsible for moving directories.
elif Move_func == 2:
All_dir(thispath)
print(Fore.LIGHTCYAN_EX)
file = input(Directory_text)
path = os.getcwd()
CaMO = 'n'
while CaMO == 'n':
Jump(thispath, Jump_func_text, Directory_text)
print(Fore.LIGHTGREEN_EX)
CaMO = input(CaMO_text2)
CaMO = CaMO.lower()
path_to = os.getcwd()
shutil.move(f'{path}\\{file}', f'{path_to}\\{file}')
# Error notification.
else:
print(Fore.LIGHTRED_EX)
print('Error: This function is missing.')
# This part is responsible for renaming.
elif function == 5:
path = os.getcwd()
All_files(thispath)
print(Fore.LIGHTCYAN_EX)
file = input(file_text)
name = input(name_text)
shutil.move(f'{path}\\{file}', f'{path}\\{name}')
# This part is responsible for removing files and directories.
elif function == 6:
# Function selection: Delete file or delete directory.
print(Fore.LIGHTYELLOW_EX)
Remove_func = int(input(Remove_func_text))
# Deleting a file.
if Remove_func == 1:
# Function selection: Delete the file permanently or send it to the trash.
# REmoving FIle
print(Fore.LIGHTGREEN_EX)
REFI_func = int(input(REFI_func_text))
# Deleting the file permanently.
if REFI_func == 1:
path = os.getcwd()
All_files(thispath)
print(Fore.LIGHTCYAN_EX)
file = input(file_text)
os.remove(f'{path}\\{file}')
# Sending a file to the trash.
elif REFI_func == 2:
path = os.getcwd()
All_files(thispath)
print(Fore.LIGHTYELLOW_EX)
file = input(file_text)
send2trash(f'{path}\\{file}')
# Error notification.
else:
print(Fore.LIGHTRED_EX)
print('Error: This function is missing.')
# Removing directories.
elif Remove_func == 2:
# Function selection: Delete the directory permanently or send it to the trash.
# REDIR - REmove DIRectory
print(Fore.LIGHTGREEN_EX)
REDIR_func = int(input(REDIR_func_text))
# Removing the directory permanently.
if REDIR_func == 1:
path = os.getcwd()
All_files(thispath)
print(Fore.LIGHTCYAN_EX)
file = input(Directory_text)
shutil.rmtree(f'{path}\\{file}')
# Sending directory to trash.
elif REDIR_func == 2:
path = os.getcwd()
All_files(thispath)
print(Fore.LIGHTCYAN_EX)
file = input(Directory_text)
send2trash(f'{path}\\{file}')
# Error notification.
else:
print(Fore.LIGHTRED_EX)
print('Error: This function is missing.')
# This part is responsible for reading files.
elif function == 7:
All_files(thispath)
print(Fore.LIGHTCYAN_EX)
file = input(file_text)
FO = open(file, 'r')
print(Fore.RESET)
for line in FO:
print(line)
FO.close()
# This is the part that is responsible for overwriting files.
elif function == 8:
All_files(thispath)
file = input(file_text)
FO = open(file, 'w')
FW = 'y'
while FW == 'y':
print(Fore.LIGHTCYAN_EX + FO_txt_text)
print(Fore.RESET)
FO_txt = input('')
FO.write(FO_txt + '\n')
print(Fore.LIGHTGREEN_EX)
FW = input(FW_text)
FW = FW.lower()
FO.close()
# This part is responsible for opening the image.
elif function == 9:
All_files(thispath)
file = input(file_text)
img = Image.open(file)
img.show()
input(Enter)
# The part responsible for closing the program.
elif function == 10:
print(Fore.RESET)
start = False
# Error notification.
else:
print(Fore.LIGHTRED_EX)
print('Error: This function is missing.')
except FileNotFoundError:
print(Fore.LIGHTRED_EX)
print('Error: The file or directory does not exist.')
except:
print(Fore.LIGHTRED_EX)
print('ERROR')