-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_manager.py
More file actions
189 lines (152 loc) · 5.13 KB
/
file_manager.py
File metadata and controls
189 lines (152 loc) · 5.13 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
import os
import random
import shutil
req_main = ''
req = ''
sec_req = ''
opeSys = os.name
with open('manual.txt', 'r', encoding='utf-8') as file:
print(*file)
def separating_reqest(request):
global req_main
global req
global sec_req
req_array = []
request = request.lstrip()
req_array = request.split(' ')
if len(req_array) == 2:
req_main = req_array[0]
req = req_array[1]
print(req_array)
print(req_main, req)
elif len(req_array) == 1:
req_main = req_array[0]
print(req_main)
elif len(req_array) == 3:
req_main = req_array[0]
req = req_array[1]
sec_req = req_array[2]
print(req_array)
print(req_main, req, sec_req)
def cur_dir():
full_path = os.getcwd()
cur_path = full_path.split('\\')
pwd = cur_path[len(cur_path)-1]
print(pwd, '\n')
def dir_rem(dir_name):
os.rmdir(dir_name)
print(f'Директория {dir_name} удалена', '\n')
def mkdir_py(dir_name):
if not os.path.isdir(dir_name):
os.umask(0)
os.mkdir(dir_name,0o777)
print(f'Директория с именем {dir_name} создана', '\n')
else:
print('Директория с таким именем уже существует')
def F_list(dir_name):
List = os.listdir()
for i in range(len(List)):
print(List[i])
print('\n')
def touch(file_name):
global opeSys
if opeSys == 'posix':
os.system(open(file_name + '.txt'))
elif opeSys != 'posix':
if not os.path.isfile(file_name):
text_file = open(file_name + '.txt', 'w+')
text_file.write('')
file_name += '.txt'
os.startfile(file_name)
print('Текстовый файл создан!')
def open_file(file_name):
with open(file_name, 'r', encoding='utf-8') as file:
print(*file)
def rename(old_Fname, new_Fanme):
old_Fname += '.txt'
new_Fanme += '.txt'
os.rename(old_Fname, new_Fanme)
print(f'Теперь файл {old_Fname} называется {new_Fanme}!')
def rm(file_name):
os.remove(file_name)
print(f'Файл с именем {file_name} - удалён')
def moveto(file_name, dir_name):
os.replace(file_name, f'{dir_name}/{file_name}')
print(f'Файл {file_name} был перемещён в директорию {dir_name} !')
def chdir(dir_name):
if dir_name != 'back':
os.chdir(dir_name)
print(f'Рабочая директория изменена на {dir_name}.')
else:
os.chdir('..')
print('Возврат к предыдущей директории')
def copy_file(file_name, second_file):
shutil.copyfile(file_name, second_file)
print(f'Файл {file_name} скопирован')
def copy_folder(file_name, dir_name):
if not os.path.isdir(dir_name):
shutil.copy(file_name, dir_name)
print(f'Файл {file_name} был скопирован в директорию {dir_name}')
def edit_file(file_name):
global opeSys
if opeSys == 'posix':
os.system(open(file_name + '.txt'))
elif opeSys != 'posix':
file_name += '.txt'
os.startfile(file_name)
print(f'Файл {file_name} был изменён')
user_input = str(os.getcwd()) + ': '
def man():
open_file('manual.txt')
requ = input('Введите запрос: ')
requ.lower()
while len(requ) != ' ':
exit_check = requ.lower()
if exit_check == 'exit':
a = int(random.random() * 100)
if a % 5 == 0:
print('\nSee you next time!')
else:
print('\nShutting down...')
exit()
else:
try:
separating_reqest(requ)
if req_main == 'mkdir':
mkdir_py(req)
if req_main == 'remdir':
dir_rem(req)
if req_main == 'pwd':
cur_dir()
if req_main == 'ls':
F_list(req)
if req_main == 'touch':
touch(req)
if req_main == 'rm':
rm(req)
if req_main == 'moveto':
moveto(req, sec_req)
if req_main == 'rename':
rename(req, sec_req)
if req_main == 'open':
open_file(req)
if req_main == 'chdir':
chdir(req)
if req_main == 'edit':
edit_file(req)
if req_main == 'copyFile':
copy_file(req, sec_req)
if req_main == 'copyto':
copy_folder(req, sec_req)
if req_main == 'copyto':
copy_folder(req, sec_req)
if req_main == 'man':
man()
user_input = str(os.getcwd()) + ': '
except:
continue
finally:
requ = input(user_input)
print('Запрос: ', req_main)
if req != '':
print('Параметр запроса: ', req)