using System; using System.IO; class Program { static void Main() { const string inputDir = "/var/data"; const string outputFile = "/var/result/data.txt"; try { using (var writer = new StreamWriter(outputFile)) { var files = Directory.GetFiles(inputDir); foreach (var file in files) { using (var reader = new StreamReader(file)) { string firstLine = reader.ReadLine(); if (!string.IsNullOrEmpty(firstLine)) { writer.WriteLine(firstLine); } } } } Console.WriteLine($"Файл {outputFile} успешно создан."); } catch (Exception ex) { Console.WriteLine($"Ошибка: {ex.Message}"); } } }