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

29 lines
890 B
C#
Raw Normal View History

2023-10-16 21:25:24 +04:00
var dir = new DirectoryInfo("/var/data");
2023-10-08 17:01:18 +04:00
var files = dir.GetFiles();
string? oldFilePath = null;
2023-10-16 21:25:24 +04:00
var newFilePathTest = new DirectoryInfo("/var/result");
2023-10-08 17:01:18 +04:00
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("Нет исходных файлов для чтения.");
}