Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.9 KiB

  1. /*+*******************************************************************************************
  2. Project :
  3. File : dirscan.c
  4. Summary :
  5. Classes / Fcns :
  6. Notes / Revisions :
  7. *******************************************************************************************+*/
  8. using System;
  9. using System.IO;
  10. namespace filename
  11. {
  12. public class DirScan
  13. {
  14. /*---------------------------------------------------------
  15. Public Member Fcns
  16. ----------------------------------------------------------*/
  17. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++
  18. Method: public void BeginScan()
  19. Summary:
  20. Args:
  21. Modifies:
  22. Returns:
  23. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  24. static public void BeginScan( string StartDir, string FileFilter, string OutputFile, int MaxLen, bool Recurse, bool Append, bool WriteHeader)
  25. {
  26. StreamWriter os = null;
  27. DirectoryInfo dir, subDir;
  28. String FullName;
  29. long FileSize;
  30. DateTime CreationDate;
  31. if ( "" != OutputFile )
  32. {
  33. if ( true == Append)
  34. {
  35. os = File.AppendText(OutputFile);
  36. }
  37. else
  38. {
  39. os = File.CreateText(OutputFile);
  40. }
  41. }
  42. if ( null != os && true == WriteHeader )
  43. {
  44. os.WriteLine("Filename Length Checker");
  45. os.WriteLine("Parameters:");
  46. os.WriteLine("\tStarting Directory = {0}",StartDir);
  47. os.WriteLine("\tFile Filter = {0}",FileFilter);
  48. if ( true == Recurse)
  49. {
  50. os.WriteLine("\tRecurse directories = TRUE");
  51. }
  52. else
  53. {
  54. os.WriteLine("\tRecurse directories = FALSE");
  55. }
  56. os.WriteLine("\tOutput File = {0}",OutputFile);
  57. os.WriteLine("\tMax File Name Length = {0}",MaxLen);
  58. os.WriteLine("=============================================");
  59. os.WriteLine("Scanning Directory -> {0}",StartDir);
  60. os.WriteLine("-------------------------------------------------------------");
  61. }
  62. Console.WriteLine("Scanning Directory -> {0}",StartDir);
  63. dir = new DirectoryInfo(StartDir);
  64. foreach (FileInfo f in dir.GetFiles(FileFilter))
  65. {
  66. if ( MaxLen < f.Name.Length )
  67. {
  68. Console.WriteLine("{0}", f.Name);
  69. if ( null != os )
  70. {
  71. os.WriteLine("{0}", f.FullName);
  72. }
  73. }
  74. }
  75. if ( true == Recurse )
  76. {
  77. foreach ( DirectoryInfo d in dir.GetDirectories("*") )
  78. {
  79. if ( null != os )
  80. {
  81. os.WriteLine("Scanning Directory -> {0}",d.FullName);
  82. os.WriteLine("-------------------------------------------------------------");
  83. os.Flush();
  84. os.Close();
  85. os = null;
  86. }
  87. Console.WriteLine("Scanning Directory -> {0}",StartDir);
  88. DirScan.BeginScan(d.FullName, FileFilter, OutputFile, MaxLen, Recurse, true, false);
  89. }
  90. }
  91. if ( null != os )
  92. {
  93. os.Flush();
  94. os.Close();
  95. }
  96. }// public void BeginScan
  97. }
  98. } // namespace filescan