File44. Даны три файла одного и того же типа, но разного размера. Заменить содержимое самого длинного файла на содержимое самого короткого.
Решение на Python 3:
# -*- coding: utf-8 -*-
import random
import sys
import os
from shutil import copyfile
file1 = "file42_1.txt"
file2 = "file42_2.txt"
file3 = "file42_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(min_file, max_file)
except:
print("Error: ", sys.exc_info())