예제 #1
0
 public static void PrintStudent(KeyValuePair <string, double> student)
 {
     OutputWriter.WriteMessageOnNewLine($"{student.Key} - {student.Value}");
 }
예제 #2
0
        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);
                }
            }
        }