DAS_2024_1/aleikin_artem_lab_2/MySolution/ConsoleApp1/Program.cs

37 lines
991 B
C#

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