distributed-computing/tasks/nikiforova-ts/Lab_2/worker-1/Program.cs

34 lines
1009 B
C#
Raw Normal View History


using System;
using System.IO;
using System.Text;
string[] files = Directory.GetFiles("../../../../var/data");
string minFilePath = "";
long minFileNameLength = long.MaxValue;
foreach (var filePath in files)
{
FileInfo fileInfo = new FileInfo(filePath);
string fileName = Path.GetFileName(filePath);
if (fileName.Length < minFileNameLength)
{
minFileNameLength = fileName.Length;
minFilePath = filePath;
}
}
using (FileStream sourceStream = File.OpenRead(minFilePath))
{
byte[] buffer = new byte[sourceStream.Length];
await sourceStream.ReadAsync(buffer, 0, buffer.Length);
string text = Encoding.Default.GetString(buffer);
using (FileStream targetStream = new FileStream("../../../../var/result/data.txt", FileMode.OpenOrCreate))
{
targetStream.SetLength(0);
byte[] textBytes = Encoding.Default.GetBytes(text);
await targetStream.WriteAsync(textBytes, 0, textBytes.Length);
}
}