MiroslavKisov

Files

Nov 21st, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04.Files
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             Dictionary<string, long> data = new Dictionary<string, long>();
  12.             List<string> filePaths = new List<string>();
  13.             int numberOfFilePaths = int.Parse(Console.ReadLine());
  14.             bool isDataFound = false;
  15.  
  16.             for (int i = 0; i < numberOfFilePaths; i++)
  17.             {
  18.                 string inputFilePaths = Console.ReadLine();
  19.                 filePaths.Add(inputFilePaths);
  20.             }
  21.  
  22.             string query = Console.ReadLine();
  23.             var queryArgs = query
  24.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  25.                 .ToList();
  26.  
  27.             for (int i = 0; i < filePaths.Count; i++)
  28.             {
  29.                 var pathArgs = filePaths[i]
  30.                     .Split(new char[] { '\\' },StringSplitOptions.RemoveEmptyEntries)
  31.                     .ToList();
  32.                 var fileWithSize = pathArgs[pathArgs.Count - 1]
  33.                     .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
  34.                     .ToList();
  35.  
  36.                 string file = fileWithSize[0];
  37.                 long fileSize = long.Parse(fileWithSize[fileWithSize.Count - 1]);
  38.                 string rootDir = pathArgs[0];
  39.                 var fileNameSplitted = file.Split('.').ToList();
  40.                 string fileExtention = fileNameSplitted[fileNameSplitted.Count - 1];
  41.  
  42.                 if (fileExtention == queryArgs[0] && rootDir == queryArgs[2])
  43.                 {
  44.                     isDataFound = true;
  45.  
  46.                     if (!data.ContainsKey(file))
  47.                     {
  48.                         data.Add(file, fileSize);
  49.                     }
  50.                     else
  51.                     {
  52.                         data[file] = fileSize;
  53.                     }
  54.                 }
  55.             }
  56.             if (isDataFound)
  57.             {
  58.                 foreach (var d in data.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  59.                 {
  60.                     Console.WriteLine($"{d.Key} - {d.Value} KB");
  61.                 }
  62.             }
  63.             else
  64.             {
  65.                 Console.WriteLine("No");
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment