private void Initialize() { m_DirStats = null; m_GetStatsCount = 0; m_DataLevels = 1; m_FileFilter = "*.*"; }
public void AddNestedStats(DirStats NewStats, bool StoreNested) { ulong DeepestLevel = NewStats.NestedDeepestLevel + 1; this.NestedFileSize += NewStats.NestedFileSize + NewStats.LocalFileSize; this.NestedHiddenSize += NewStats.NestedHiddenSize + NewStats.LocalHiddenSize; this.NestedNumDirs += NewStats.NestedNumDirs + NewStats.LocalNumDirs; this.NestedNumFiles += NewStats.NestedNumFiles + NewStats.LocalNumFiles; this.NestedNumHidden += NewStats.NestedNumHidden + NewStats.LocalNumHidden; this.NestedNumSystem += NewStats.NestedNumSystem + NewStats.LocalNumSystem; this.NestedSystemSize += NewStats.NestedSystemSize + NewStats.LocalSystemSize; this.TotalErrors += NewStats.TotalErrors; if (this.NestedDeepestLevel < DeepestLevel) { this.NestedDeepestLevel = DeepestLevel; } if (StoreNested == true) { m_ChildList.AddLast(NewStats); } }
private void AddUpDir(DirectoryInfo CurDirInfo, DirStats CurDirStats, int CurLevel) { // All the real work gets done here, this function adds up the size of the current // folder and recursively calls itself for any directories found. The "CurLevel" is used // to decide whether stats gathered need to be stored for display or just added to the // previous directory Stats. FileInfo[] FileList; // Arbitrary check for really large nesting - which is most likely an infinite loop. if (m_DataLevels - CurLevel > 1024) { throw new CountException("Too many nested folders, possible infinite directory loop detected."); } //populate local settings try { FileList = CurDirInfo.GetFiles(m_FileFilter); } catch (ArgumentException) { throw new CountException(string.Format("Illegal characters in file filter \"{0}\".", m_FileFilter)); } foreach (FileInfo FI in FileList) { CurDirStats.LocalNumFiles++; CurDirStats.LocalFileSize += (ulong)FI.Length; if ((FI.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { //hidden file CurDirStats.LocalHiddenSize += (ulong)FI.Length; CurDirStats.LocalNumHidden++; } if ((FI.Attributes & FileAttributes.System) == FileAttributes.System) { //hidden file CurDirStats.LocalSystemSize += (ulong)FI.Length; CurDirStats.LocalNumSystem++; } } //recursively call directories foreach (DirectoryInfo NewDir in CurDirInfo.GetDirectories()) { DirStats NewDirStats = null; if ((m_SkipReparsePoints == true) && ((NewDir.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint)) { // Skip - this a junction point. continue; } NewDirStats = new DirStats(); NewDirStats.DirName = NewDir.FullName; try { AddUpDir(NewDir, NewDirStats, CurLevel - 1); } catch (UnauthorizedAccessException) { CurDirStats.TotalErrors++; } catch (IOException) { CurDirStats.TotalErrors++; } CurDirStats.LocalNumDirs++; if (CurLevel > 0) { CurDirStats.AddNestedStats(NewDirStats, true); } else { CurDirStats.AddNestedStats(NewDirStats, false); } } }
private void SetNewBaseDir(string NewBaseDir) { m_DirStats = new DirStats(); m_DirStats.DirName = Util.GetTestedFullPath(NewBaseDir); }
private void PrintStatLine(DirStats CurStats, int Level, string Prefix, bool LastChild) { // Real work done for printing line items - this item will recursively call itself as // it finds subfolders. Levels, Prefix, and LastChild are used to nest the output, with // LastChild a hint that it's the last folder at this level allowing the line characters // to be closed. (Best way to understand this is to study the output of a bunch of nested // folders.) int i; int TLen; string DirName; int ColumnWidth = m_DisplayColumnSize - 8; char SpacerCharacter = GetSpacerCharacter(Level); // Check inputs if (Level * 3 > ColumnWidth - 1) { return; } // Space to name if (Level > 0) { i = Prefix.Length + 3; m_Out.Write(Prefix); if (LastChild) { m_Out.Write(m_Lines[m_LI, 0]); } else { m_Out.Write(m_Lines[m_LI, 1]); } } else { i = 0; } // Print name if (CurStats.TotalErrors > 0) { DirName = "*"; } else { DirName = ""; } if (Level == 0) { DirName += CurStats.DirName; } else { DirName += System.IO.Path.GetFileName(CurStats.DirName); } // Truncate name if it's too long if (DirName.Length + i > ColumnWidth - 1) { TLen = ColumnWidth - i - 2; if (TLen < 0) { TLen = 0; } DirName = DirName.Substring(0, TLen); } i += DirName.Length; m_Out.Write(DirName); // Space to Size for (; i < ColumnWidth; i++) { if (i % 2 == 0) { m_Out.Write(SpacerCharacter); } else { m_Out.Write(" "); } } // Print Size m_Out.WriteLine("{0,7}", Util.ULongToHumanReadable(CurStats.LocalFileSize + CurStats.NestedFileSize)); // Child Items if (Level < m_Levels) // Print children if it will fit { i = 0; if (LastChild) { Prefix += " "; } else { Prefix += m_Lines[m_LI, 2]; } CurStats.GetChildStats().EnumerateListHeadToTail = this.PrintItemsInOrder; foreach (DirStats NewStat in CurStats.GetChildStats()) { i++; if (i < CurStats.GetChildStats().Count) { PrintStatLine(NewStat, Level + 1, Prefix, false); } else { PrintStatLine(NewStat, Level + 1, Prefix, true); } } } }