File45. Даны три файла одного и того же типа, но разного размера. Заменить содержимое самого короткого файла на содержимое самого длинного.
Решение на Python 3:
# -*- coding: utf-8 -*-
import random
import sys
import os
from shutil import copyfile
file1 = "file45_1.txt"
file2 = "file45_2.txt"
file3 = "file45_3.txt"
try:
size1 = os.stat(file1).st_size
size2 = os.stat(file2).st_size
size3 = os.stat(file3).st_size
min_size = size1
min_file = file1
max_size = size1
max_file = file1
if size2 < min_size:
min_size = size2
min_file = file2
if size3 < min_size:
min_size = size3
min_file = file3
if size2 > max_size:
max_size = size2
max_file = file2
if size3 > max_size:
max_size = size3
max_file = file3
print("min size: ", min_size)
print("min file: ", min_file)
print("max size: ", max_size)
print("max file: ", max_file)
## copyfile(source, destination)
copyfile(max_file, min_file)
except:
print("Error: ", sys.exc_info())