public void StartReadingCommands() { OutputWriter.WriteMessage($"{SessionData.currentPath}>"); string input = Console.ReadLine(); input = input?.Trim(); while (input != EndCommand1 && input != EndCommand2) { if (!string.IsNullOrWhiteSpace(input)) { this.interpreter.InterpredCommand(input); } OutputWriter.WriteMessage($"{SessionData.currentPath}>"); input = Console.ReadLine(); input = input.Trim(); } if (SessionData.taskPool.Count != 0) { Task.WaitAll(SessionData.taskPool.ToArray()); } }
public void TraverseDirectory(int depth) { //test if (depth == 0) { depth = 101; } else { depth--; } //endTest OutputWriter.WriteEmptyLine(); int initialIdentation = SessionData.currentPath.Split('\\').Length; Queue <string> subFolders = new Queue <string>(); subFolders.Enqueue(SessionData.currentPath); while (subFolders.Count != 0) { string currentPath = subFolders.Dequeue(); int identation = currentPath.Split('\\').Length - initialIdentation; if (depth - identation < 0) { break; } OutputWriter.WriteMessageOnNewLine($"{new string('-', identation)}{currentPath}"); try { foreach (var dir in Directory.GetDirectories(currentPath)) { int indexOfLastSlash = dir.LastIndexOf("\\"); for (int i = 0; i < indexOfLastSlash; i++) { OutputWriter.WriteMessage("+"); } var newDir = dir.Substring(indexOfLastSlash); OutputWriter.WriteMessageOnNewLine(newDir); } foreach (var file in Directory.GetFiles(currentPath)) { int indexOfLastSlash = file.LastIndexOf("\\"); for (int i = 0; i < indexOfLastSlash; i++) { OutputWriter.WriteMessage("-"); } var newFile = file.Substring(indexOfLastSlash); OutputWriter.WriteMessageOnNewLine(newFile); } foreach (string directoryPath in Directory.GetDirectories(currentPath)) { if (depth != 101) { subFolders.Enqueue(directoryPath); } } } catch (UnauthorizedAccessException) { OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage); } } }