distributed-computing/tasks/fomichev-ai/lab_2/worker-1/Program.cs

29 lines
890 B
C#

var dir = new DirectoryInfo("/var/data");
var files = dir.GetFiles();
string? oldFilePath = null;
var newFilePathTest = new DirectoryInfo("/var/result");
string? fileName = null;
long minFileName = long.MaxValue;
foreach(var file in files)
{
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.Name);
if(fileNameWithoutExtension.Length < minFileName)
{
minFileName = fileNameWithoutExtension.Length;
oldFilePath = Path.GetFullPath(file.FullName);
fileName = file.Name;
}
}
if (oldFilePath != null)
{
foreach (var file in newFilePathTest.GetFiles())
file.Delete();
File.Copy(oldFilePath, newFilePathTest.FullName + "/" + fileName, true);
Console.WriteLine("Сервис 1 отработал успешно!");
} else
{
throw new Exception("Нет исходных файлов для чтения.");
}