
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);
        }
}
