DAS_2024_1/rogashova_ekaterina_lab_2/worker-1/findfile.py

24 lines
657 B
Python
Raw Permalink Normal View History

2024-10-20 21:59:10 +04:00
import os
import shutil
def find_shortest_file(directory):
shortest_file = None
shortest_file_length = float('inf')
for file in os.listdir(directory):
file_path = os.path.join(directory, file)
if os.path.isfile(file_path) and len(file) < shortest_file_length:
shortest_file = file_path
shortest_file_length = len(file)
return shortest_file
def move_file(source, destination):
shutil.move(source, destination)
directory = "/var/data"
shortest_file = find_shortest_file(directory)
if shortest_file is not None:
destination = "/var/result/data.txt"
move_file(shortest_file, destination)