Advertisement
Prohause

Untitled

Jun 18th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. public static void TraverseDirectory(int depth)
  2. {
  3. OutputWriter.WriteEmptyLine();
  4. var initialIdentention = SessionData.CurrentPath.Split('\\').Length;
  5. var subFolders = new Queue<string>();
  6. subFolders.Enqueue(SessionData.CurrentPath);
  7.  
  8. while (subFolders.Count != 0)
  9. {
  10. var currentPath = subFolders.Dequeue();
  11. var identation = currentPath.Split('\\').Length - initialIdentention;
  12.  
  13. OutputWriter.WriteMessageOnNewLine($"{new string('-', identation)}{currentPath}");
  14. try
  15. {
  16. foreach (var file in Directory.GetFiles(currentPath))
  17. {
  18. var output = file.Remove(0, currentPath.Length);
  19. OutputWriter.WriteMessageOnNewLine(new string('-', currentPath.Length) + output);
  20. }
  21. if (depth - identation <=0)
  22. {
  23. break;
  24. }
  25. foreach (var directoryPath in Directory.GetDirectories(currentPath))
  26. {
  27. subFolders.Enqueue(directoryPath);
  28. }
  29. }
  30. catch (UnauthorizedAccessException)
  31. {
  32. OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement