private static ScanFolderResult ScanFolder(string folder, bool log = true) { var res = new ScanFolderResult(folder); try { IEnumerable <string> subFolders = Directory.GetDirectories(folder); Parallel.ForEach(subFolders, subFolder => { if (log) { Console.WriteLine(subFolder); } var subFolderResult = ScanFolder(subFolder, false); lock (res) { res.AddSubFolder(subFolderResult); } }); res.FolderSize = GetFolderSize(folder); } catch (UnauthorizedAccessException e) { } return(res); }
private static ScanFolderResult ScanFolder(string folder, bool log = true) { var res = new ScanFolderResult(folder); try { IEnumerable<string> subFolders = Directory.GetDirectories(folder); Parallel.ForEach(subFolders, subFolder => { if (log) { Console.WriteLine(subFolder); } var subFolderResult = ScanFolder(subFolder, false); lock (res) { res.AddSubFolder(subFolderResult); } }); res.FolderSize = GetFolderSize(folder); } catch (UnauthorizedAccessException e) { } return res; }
private static IEnumerable<ScanFolderResult> GetAllFolders(ScanFolderResult scanFolderResult) { yield return scanFolderResult; foreach (var subFolder in scanFolderResult.SubFolders.SelectMany(GetAllFolders)) { yield return subFolder; } }
private static IEnumerable <ScanFolderResult> GetAllFolders(ScanFolderResult scanFolderResult) { yield return(scanFolderResult); foreach (var subFolder in scanFolderResult.SubFolders.SelectMany(GetAllFolders)) { yield return(subFolder); } }
private static IEnumerable<FolderDiff> CompareFolders(ScanFolderResult scanFolderResult, ScanFolderResult previousFolderScan) { var previousFolders = GetAllFolders(previousFolderScan).ToDictionary(f => f.Folder, f => f.FolderSize); foreach (var folder in GetAllFolders(scanFolderResult)) { var diff = folder.FolderSize; if (previousFolders.ContainsKey(folder.Folder)) { diff = folder.FolderSize - previousFolders[folder.Folder]; } yield return new FolderDiff{ Folder = folder.Folder, Diff = diff }; } }
private static IEnumerable <FolderDiff> CompareFolders(ScanFolderResult scanFolderResult, ScanFolderResult previousFolderScan) { var previousFolders = GetAllFolders(previousFolderScan).ToDictionary(f => f.Folder, f => f.FolderSize); foreach (var folder in GetAllFolders(scanFolderResult)) { var diff = folder.FolderSize; if (previousFolders.ContainsKey(folder.Folder)) { diff = folder.FolderSize - previousFolders[folder.Folder]; } yield return(new FolderDiff { Folder = folder.Folder, Diff = diff }); } }
private static void WritePreviousFolderScan(ScanFolderResult scanFolderResult) { var path = Path.Combine(scanFolderResult.Folder, ScanResultFilename); new XmlSerializer(typeof(ScanFolderResult)).Serialize(File.Create(path), scanFolderResult); }
public void AddSubFolder(ScanFolderResult subFolderResult) { SubFolders.Add(subFolderResult); }