55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
|
var directoryPath = Environment.GetEnvironmentVariable("APP_DIR");
|
|||
|
if (directoryPath == null)
|
|||
|
{
|
|||
|
Console.WriteLine("Не найден переменная среды адреса");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var inputFilesPath = Path.Combine(directoryPath, "data");
|
|||
|
var outputFilePath = Path.Combine(directoryPath, "result");
|
|||
|
|
|||
|
Console.WriteLine($"Входная папка: {inputFilesPath}");
|
|||
|
Console.WriteLine($"Выходная папка: {outputFilePath}");
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
if (Directory.Exists(inputFilesPath))
|
|||
|
{
|
|||
|
var files = Directory.GetFiles(inputFilesPath);
|
|||
|
|
|||
|
if (files.Length > 0)
|
|||
|
{
|
|||
|
var fileWithMostLines = files
|
|||
|
.Select(filePath => new { FilePath = filePath, LineCount = File.ReadLines(filePath).Count() })
|
|||
|
.OrderByDescending(x => x.LineCount)
|
|||
|
.First();
|
|||
|
|
|||
|
Console.WriteLine($"Файл с наибольшим количеством строк: {fileWithMostLines.FilePath}");
|
|||
|
Console.WriteLine($"Количество строк в файле: {fileWithMostLines.LineCount}");
|
|||
|
|
|||
|
string outputFileName = "inputFileFor2Program.txt";
|
|||
|
string outputFilePathWithFileName = Path.Combine(outputFilePath, outputFileName);
|
|||
|
|
|||
|
if (File.Exists(outputFilePathWithFileName))
|
|||
|
{
|
|||
|
Console.WriteLine($"Файл {outputFilePathWithFileName} уже существует удалим его");
|
|||
|
File.Delete(outputFilePathWithFileName);
|
|||
|
}
|
|||
|
File.Copy(fileWithMostLines.FilePath, outputFilePathWithFileName);
|
|||
|
|
|||
|
Console.WriteLine($"Файл перемещен в {outputFilePathWithFileName}");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Console.WriteLine("В директории нет файлов.");
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Console.WriteLine("Указанной директории не существует.");
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
Console.WriteLine(ex.ToString());
|
|||
|
}
|