Created
March 13, 2019 01:55
-
-
Save IngIeoAndSpare/2a03d852249a814c02a16b53b9462893 to your computer and use it in GitHub Desktop.
dir file checker
This file contains 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; | |
using System.Threading.Tasks; | |
namespace fileChecker | |
{ | |
internal class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
string path = @""; // example : @"Z:\" | |
//check dir size | |
Task directorySizeCheck = Task.Factory.StartNew(() => | |
{ | |
DirectorySize(new DirectoryInfo(path + level), true); | |
}); | |
//check file length | |
Task fileLengthCheck = Task.Factory.StartNew(() => | |
{ | |
DirectoryFileLength(new DirectoryInfo(path + level), level); | |
}); | |
//check dir length | |
Task directoryLengthCheck = Task.Factory.StartNew(() => | |
{ | |
DirectoryLength(new DirectoryInfo(path + level), level); | |
}); | |
//wait all checker work end | |
Task.WaitAll(new Task[3]{directorySizeCheck, fileLengthCheck, directoryLengthCheck}); | |
} | |
public static double DirectorySize(DirectoryInfo dInfo, bool includeSubDir) | |
{ | |
double totalSize = dInfo.EnumerateFiles().Sum(file => file.Length); | |
if (includeSubDir) totalSize += dInfo.EnumerateDirectories().Sum(dir => DirectorySize(dir, true)); | |
return totalSize; | |
} | |
public static void DirectoryLength(DirectoryInfo dInfo, string level) | |
{ | |
Console.WriteLine(level+ " level fileLength : " + dInfo.GetDirectories().Length); | |
} | |
public static void DirectoryFileLength(DirectoryInfo dInfo, string level) | |
{ | |
int fileLength = Directory.GetFiles(dInfo.FullName, "*.*", SearchOption.AllDirectories).Length; | |
Console.WriteLine(level + " level fileLength : " + fileLength); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment