Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void TraverseDirectory(int depth)
- {
- OutputWriter.WriteEmptyLine();
- var initialIdentention = SessionData.CurrentPath.Split('\\').Length;
- var subFolders = new Queue<string>();
- subFolders.Enqueue(SessionData.CurrentPath);
- while (subFolders.Count != 0)
- {
- var currentPath = subFolders.Dequeue();
- var identation = currentPath.Split('\\').Length - initialIdentention;
- OutputWriter.WriteMessageOnNewLine($"{new string('-', identation)}{currentPath}");
- try
- {
- foreach (var file in Directory.GetFiles(currentPath))
- {
- var output = file.Remove(0, currentPath.Length);
- OutputWriter.WriteMessageOnNewLine(new string('-', currentPath.Length) + output);
- }
- if (depth - identation <=0)
- {
- break;
- }
- foreach (var directoryPath in Directory.GetDirectories(currentPath))
- {
- subFolders.Enqueue(directoryPath);
- }
- }
- catch (UnauthorizedAccessException)
- {
- OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement