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.

39 lines
1.3 KiB

  1. using System;
  2. using System.IO;
  3. namespace Microsoft.Fusion.ADF
  4. {
  5. public class DirScanner
  6. {
  7. public static void BeginScan(IFileOperator ifo, string rootPath)
  8. {
  9. if((ifo != null) && (rootPath != null))
  10. {
  11. string fullPath = Path.GetFullPath(rootPath);
  12. if(Directory.Exists(fullPath)) ScanDirectory(ifo, fullPath, ""); // This path is a directory
  13. else Console.WriteLine(fullPath + " is not a valid directory.");
  14. }
  15. }
  16. public static void ScanDirectory(IFileOperator ifo, string rootPath, string relPathDir)
  17. {
  18. string currDir = Path.Combine(rootPath, relPathDir);
  19. //string currDir = String.Concat(rootPath, relPathDir);
  20. // Process the list of files found in the directory
  21. string [] fileEntries = Directory.GetFiles(currDir);
  22. foreach(string fileName in fileEntries) ifo.ProcessFile(rootPath, relPathDir, Path.GetFileName(fileName));
  23. // Recurse into subdirectories of this directory
  24. string [] subdirEntries = Directory.GetDirectories(currDir);
  25. foreach(string subdir in subdirEntries)
  26. {
  27. // Get the end directory and tag it onto relPathDir
  28. string tempRelPathDir = Path.Combine(relPathDir, subdir.Substring(currDir.Length+1));
  29. ifo.ProcessDirectory(rootPath, tempRelPathDir);
  30. ScanDirectory(ifo, rootPath, tempRelPathDir);
  31. }
  32. }
  33. }
  34. }