Created
March 12, 2017 10:30
-
-
Save Soulstorm50/ac84362891bf87677577fd70187ebb40 to your computer and use it in GitHub Desktop.
C# файловый анализ содержимого всех каталогов системы
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
public class FileLength | |
{ | |
public static void Main() | |
{ | |
//запись всех файлов и файлов в подпапках в массив | |
string[] AllFiles = Directory.GetFiles(@"D:\\рабочая", "*", SearchOption.AllDirectories); | |
//сортировка OrderBy(g => g.Key) по расширению AllFiles.GroupBy(Path.GetExtension) в разные массивы | |
//сортировка OrderBy(g => g.Count()) по количеству файлов | |
var extensionGroups = AllFiles.GroupBy(Path.GetExtension).OrderBy(g => g.Count()); | |
//вывод типа расширения и их количество не повторяясь | |
foreach (var group in extensionGroups) | |
Console.WriteLine("файлов с расширением {0} - {1} штук ", group.Key, group.Count() ); | |
Console.WriteLine(); | |
//тут происходит сам подсчет в байтах определенного типа файлов или всех | |
DirectoryInfo di = new DirectoryInfo(@"D:\\рабочая"); | |
long sum = 0; | |
foreach (var fi in di.GetFiles("*.txt", SearchOption.AllDirectories))//задаем разрешение по которому ищем | |
{ | |
sum += fi.Length;//подсчет байтов по заданаму разрешению | |
} | |
Console.WriteLine("{0} bytes", sum);//вывод | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment