blob: 593df5b618a893ffba1e91c8fd4647f1caec5d6c (
plain)
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
|
import os
CHUNK_SIZE = 1024
write_path = os.path.join(os.getcwd(), 'task2_data_1.txt')
read_path = os.path.join(os.getcwd(), 'task2_data_2.txt')
try:
write_file = open(write_path, 'a')
read_file = open(read_path)
except FileNotFoundError as e:
exception_path = str(e).strip('[Errno 2] No such file or directory:')[1:-1]
print(f'"{exception_path}" не существует')
except PermissionError as e:
exception_path = str(e).strip('[Errno 13] Permission denied:')[1:-1]
print(f'Файл "{exception_path}" не доступен для чтения/записи')
except IsADirectoryError as e:
exception_path = str(e).strip('[Errno 21] Is a directory:')[1:-1]
print(f'"{exception_path}" является директорией')
else:
write_file.write('\n\n\n')
data = read_file.read(CHUNK_SIZE)
write_file.write(data)
while data:
data = read_file.read(CHUNK_SIZE)
write_file.write(data)
# пожалуйста не мучайте меня я не хочу писать еще три expept'a
os.rename('task2_data_1.txt', 'task2_data_all.txt')
os.remove('task2_data_2.txt')
|