public Explorer() { DirInfo = new DirectoryData(); DirectoryList = new List <DirectoryData>(); FileList = new List <FileData>(); DriveList = new List <ServerDrive>(); }
private void CalculateGroupingFiles(ref DirectoryData currentDirData, string path) { DirectoryInfo directoryInfo = new DirectoryInfo(path); currentDirData.CountFilesLess10Mb = currentDirData.CountFilesLess10Mb + directoryInfo.GetFiles() .Where(file => file.Length <= Mb10).Count(); currentDirData.CountFiles10_50Mb = currentDirData.CountFiles10_50Mb + directoryInfo.GetFiles() .Where(file => file.Length > Mb10 && file.Length <= Mb50).Count(); currentDirData.CountFilesMore100Mb = currentDirData.CountFilesMore100Mb + directoryInfo.GetFiles() .Where(file => file.Length > Mb100).Count(); }
private DirectoryData GetFilesGroupedData(string path, DirectoryData currentDirInfo = null) { if (currentDirInfo == null) { currentDirInfo = new DirectoryData(); } DirectoryInfo directoryInfo = new DirectoryInfo(path); IEnumerable <DirectoryInfo> dirs; try { dirs = directoryInfo.EnumerateDirectories(); foreach (DirectoryInfo dir in dirs) { if (!((dir.Attributes & FileAttributes.System) == FileAttributes.System)) { currentDirInfo = GetFilesGroupedData(dir.FullName, currentDirInfo); } } } catch (UnauthorizedAccessException ex) { SetAccessRuleToAllow(ex); GetFilesGroupedData(path); } string[] directories = Directory.GetDirectories(path); if (directories.Length == 0) // if there is NO subdirectory { if (Directory.GetFiles(path).Length > 0) // if there are files in the current directory { CalculateGroupingFiles(ref currentDirInfo, path); } else // NO files in the current directory { foreach (string d in directories) //go to subdirectories of current dir { CalculateGroupingFiles(ref currentDirInfo, d); } } } else // there is subdirectory(es) { if (Directory.GetFiles(path).Length > 0) // if there is file in the current directory { CalculateGroupingFiles(ref currentDirInfo, path); } } return(currentDirInfo); }