Beispiel #1
0
        public static void TraverseDirectory(string path)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIdentation = path.Split('\\').Length;
            Queue <string> subFolders        = new Queue <string>();

            subFolders.Enqueue(path);

            while (subFolders.Count != 0)
            {
                string currentPath = subFolders.Dequeue();
                int    identation  = currentPath.Split('\\').Length - initialIdentation;

                if (initialIdentation - identation < 0)
                {
                    break;
                }

                try
                {
                    foreach (var directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(directoryPath);
                    }

                    OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', identation), currentPath));
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.WriteMessageOnNewLine(ExceptionMessages.UnauthorizedException);
                }
            }
        }
Beispiel #2
0
        public void TraverseDirectory(int depth)
        {
            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;

                try
                {
                    foreach (string directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(directoryPath);
                    }

                    OutputWriter.WriteMessageOnNewLine($"{new string('-', identation)}{currentPath}");

                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        int    indexOfLastSlash = file.LastIndexOf('\\');
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash) + fileName);
                    }
                }
                catch (UnauthorizedAccessException ue)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptonMessage);
                }
            }
        }
Beispiel #3
0
        public void TraverseDirectory()
        {
            try
            {
                foreach (var directory in Directory.GetDirectories(SessionData.currentPath))
                {
                    int    indexOfLastSlash = directory.LastIndexOf("\\");
                    string dirName          = directory.Substring(indexOfLastSlash);
                    OutputWriter.WriteMessageOnNewLine(dirName);
                }
                OutputWriter.WriteEmptyLine();

                foreach (var file in Directory.GetFiles(SessionData.currentPath))
                {
                    int    indexOfLastSlash = file.LastIndexOf("\\");
                    string fileName         = file.Substring(indexOfLastSlash);
                    OutputWriter.WriteMessageOnNewLine(fileName);
                }
                OutputWriter.WriteEmptyLine();
            }
            catch (UnauthorizedAccessException ex)
            {
                OutputWriter.DisplayException(ex.Message);
            }
        }
Beispiel #4
0
        private static void TryGetHelp(string input, string[] data)
        {
            if (!IsCommandValidLenght(data, 1))
            {
                return;
            }

            OutputWriter.WriteMessageOnNewLine($"{new string('_', 100)}");
            OutputWriter.WriteMessageOnNewLine($"|{"make directory - mkdir: path ",-98}|");
            OutputWriter.WriteMessageOnNewLine($"|{"traverse directory - ls: depth ",-98}|");
            OutputWriter.WriteMessageOnNewLine($"|{"comparing files - cmp: path1 path2",-98}|");
            OutputWriter.WriteMessageOnNewLine($"|{"change directory - changeDirREl:relative path",-98}|");
            OutputWriter.WriteMessageOnNewLine($"|{"change directory - changeDir:absolute path",-98}|");
            OutputWriter.WriteMessageOnNewLine($"|{"read students data base - readDb: path",-98}|");
            OutputWriter.WriteMessageOnNewLine(
                $"|{"filter {courseName} excelent/average/poor  take 2/5/all students - filterExcelent (the output is written on the console)",-98}|");
            OutputWriter.WriteMessageOnNewLine(
                $"|{"order increasing students - order {courseName} ascending/descending take 20/10/all (the output is written on the console)",-98}|");
            OutputWriter.WriteMessageOnNewLine(
                $"|{"download file - download: path of file (saved in current directory)",-98}|");
            OutputWriter.WriteMessageOnNewLine(
                $"|{"download file asinchronously - downloadAsynch: path of file (save in the current directory)",-98}|");
            OutputWriter.WriteMessageOnNewLine($"|{"get help – help",-98}|");
            OutputWriter.WriteMessageOnNewLine($"{new string('_', 100)}");
            OutputWriter.WriteEmptyLine();
        }
Beispiel #5
0
        public static void TraverseDirectory(int depth)
        {
            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    identitation = currentPath.Split('\\').Length - initialIdentation;
                if (depth - identitation < 0)
                {
                    break;
                }
                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', identitation), currentPath));

                foreach (var file in Directory.GetFiles(currentPath))
                {
                    int    indexOfLastSlash = file.LastIndexOf("\\");
                    string fileName         = file.Substring(indexOfLastSlash);
                    OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash) + fileName);
                }

                foreach (string directoryPath in Directory.GetDirectories(currentPath))
                {
                    subFolders.Enqueue(directoryPath);
                }
            }
        }
Beispiel #6
0
        public static void TraverseDirectory(string path)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIdentation = path.Split('\\').Length;
            Queue <string> subFolders        = new Queue <string>();

            subFolders.Enqueue(path);
            while (subFolders.Count != 0)
            {
            }
        }
 private static void TryGetHelp(string input, string[] data)
 {
     OutputWriter.WriteMessageOnNewLine(new string('_', 100));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "make directory - mkdir: path "));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "traverse directory - ls: depth "));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "comparing files - cmp: path1 path2"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "change directory - changeDirREl:relative path"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "change directory - changeDir:absolute path"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "read students data base - readDb: path"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "filter {courseName} excelent/average/poor  take 2/5/all students - filterExcelent (the output is written on the console)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "order increasing students - order {courseName} ascending/descending take 20/10/all (the output is written on the console)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "download file - download: path of file (saved in current directory)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "download file asinchronously - downloadAsynch: path of file (save in the current directory)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "get help – help"));
     OutputWriter.WriteMessageOnNewLine(new string('_', 100));
     OutputWriter.WriteEmptyLine();
 }
Beispiel #8
0
        public void TraverseDirectory(int depth)
        {
            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;

                ////Check depth
                if (depth - identation < 0)
                {
                    break;
                }

                ////Display current folder
                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}",
                                                                 new string('-', identation),
                                                                 currentPath));

                try
                {
                    ////Display files in current folder
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        int    indexOfLastSlash = file.LastIndexOf("\\");
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash) + fileName);
                    }

                    ////Adding subfolders
                    foreach (string directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
Beispiel #9
0
        private void DisplayHelp()
        {
            OutputWriter.WriteMessageOnNewLine($"{new string('_', 100)}");
            OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "make directory - mkdir: path "));
            OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "traverse directory - ls: depth "));
            OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "comparing files - cmp: path1 path2"));
            OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "change directory - cdRel: relative path"));
            OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "change directory - cdAbs: absolute path"));
            OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "read students data base - readDb: path"));
            OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|{1}| {2, -97}|", "filter {courseName} excelent/average/poor take 2/5/all students - filterExcelent", Environment.NewLine, "                                                           (the output is written on the console)"));
            OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|{1}|{2, -98}|", "order students - order {courseName} ascending/descending take 20/10/all", Environment.NewLine, "                                                            (the output is written on the console)"));
            OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "get help – help"));
            OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -98}|", "display data entities - display students/courses ascending/descening"));
            OutputWriter.WriteMessageOnNewLine($"{new string('_', 100)}");

            OutputWriter.WriteEmptyLine();
        }
Beispiel #10
0
        public static void TraverseDirectory(int depth)
        {
            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;

                OutputWriter.WriteMessage(new string('-', identation));
                OutputWriter.WriteMessage(currentPath);
                OutputWriter.WriteEmptyLine();

                string folderLength = new string('-', currentPath.Length);

                try
                {
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        var fileName = file.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).Last().ToString();
                        OutputWriter.WriteMessageOnNewLine(folderLength + "\\" + fileName);
                    }

                    foreach (var directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subfolders.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedExceptionMessage);
                }


                if (identation == depth)
                {
                    break;
                }
            }
        }
        /// <summary>
        ///     Traverse the folder of the project using a queue with BFS.
        /// </summary>
        /// <param name="path">Folders to traverse</param>
        public static void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int initialIdentation = SessionData.currentPath.Split('\\').Length;
            var subFoldersQueue   = new Queue <string>();

            subFoldersQueue.Enqueue(SessionData.currentPath);

            while (subFoldersQueue.Count != 0)
            {
                // Dequeue the folder at the start of the queue
                string currentPath = subFoldersQueue.Dequeue();
                int    identation  = currentPath.Split('\\').Length - initialIdentation;

                // stop when we reached the wanted depth
                if (depth - identation < 0)
                {
                    break;
                }

                // Print the folder path
                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', identation), currentPath));

                try
                {
                    foreach (string file in Directory.GetFiles(currentPath))
                    {
                        // get file name and replace the full path with dashes
                        int    indexOfLastSlash = file.LastIndexOf("\\");
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', indexOfLastSlash), fileName));
                    }

                    // Add all it's subfolders to the end of the queue
                    foreach (string directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFoldersQueue.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
 private void TryGetHelp(string input, string[] data)
 {
     OutputWriter.WriteMessageOnNewLine($"{new string('_', 122)}");
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "make directory - mkdir path "));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "traverse directory - ls depth "));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "comparing files - cmp path1 path2"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "change directory - cdRel relative path"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "change directory - cdAbs absolute path"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "read students data base - readDb path"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "show courseName (username) – user name may be omitted"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "filter {courseName} excelent/average/poor  take 2/5/all students - filterExcelent (the output is written on the console)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "order increasing students - order {courseName} ascending/descending take 20/10/all (the output is written on the console)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "download file - download: path of file (saved in current directory)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "download file asinchronously - downloadAsynch: path of file (save in the current directory)"));
     OutputWriter.WriteMessageOnNewLine(string.Format("|{0, -121}|", "get help – help"));
     OutputWriter.WriteMessageOnNewLine($"{new string('_', 122)}");
     OutputWriter.WriteEmptyLine();
 }
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIndentation = SessionData.currentPath.Split('\\').Length;
            Queue <string> subFolders         = new Queue <string>();

            subFolders.Enqueue(SessionData.currentPath);

            while (subFolders.Count > 0)
            {
                string currentPath = subFolders.Dequeue();

                int indentation = currentPath.Split('\\').Length - initialIndentation;

                if (depth - indentation < 0)
                {
                    break;
                }
                OutputWriter.WriteMessageOnNewLine($"{new string('-', indentation)}{currentPath}");

                try
                {
                    string[] files = Directory.GetFiles(currentPath);

                    foreach (string file in files)
                    {
                        int    indexOfLastSlash = file.IndexOf(@"\");
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine($"{new string('-', indexOfLastSlash)}{fileName}");
                    }

                    string[] directories = Directory.GetDirectories(currentPath);

                    foreach (string directory in directories)
                    {
                        subFolders.Enqueue(directory);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
Beispiel #14
0
        public static void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIdentation = SessionData.CurrentPath.Split(Separator).Length;
            Queue <string> subfolders        = new Queue <string>();

            subfolders.Enqueue(SessionData.CurrentPath);

            while (subfolders.Count > 0)
            {
                string currentPath = subfolders.Dequeue();
                int    identation  = currentPath.Split(Separator).Length - initialIdentation;

                if (depth - identation < 0)
                {
                    break;
                }

                OutputWriter.WriteMessageOnNewLine($"{new string(AlignCharacter, identation)}{currentPath}");

                try
                {
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        int    indexOfLastSlash = file.LastIndexOf(Separator);
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string(AlignCharacter, indexOfLastSlash) + fileName);
                    }

                    string identationString = new string(AlignCharacter, identation);
                    string directoryString  = $"{identationString}{currentPath}";
                    OutputWriter.WriteMessageOnNewLine(directoryString);

                    foreach (string directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subfolders.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
Beispiel #15
0
        public static void TraverseDirectory(string path)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIdentation = path.Split('\\').Length;
            Queue <string> subfolders        = new Queue <string>();

            subfolders.Enqueue(path);
            while (subfolders.Count != 0)
            {
                string currentPath = subfolders.Dequeue();
                int    identation  = currentPath.Split('\\').Length - initialIdentation;
                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', identation), currentPath));

                foreach (var dir in Directory.GetDirectories(currentPath))
                {
                    subfolders.Enqueue(dir);
                }
            }
        }
Beispiel #16
0
        public void TraverseDirectory(int path)
        {
            OutputWriter.WriteEmptyLine();
            int initialIdentation = SessionData.currentPath.Split('\\').Length;
            var subFolders        = new Queue <string>();

            subFolders.Enqueue(SessionData.currentPath);

            while (subFolders.Count != 0)
            {
                var currentPath = subFolders.Dequeue();
                int identation  = currentPath.Split('\\').Length - initialIdentation;

                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}",
                                                                 new string('-', identation),
                                                                 currentPath));

                if (path - identation < 0)
                {
                    break;
                }
                try
                {
                    foreach (string directoryPath in Directory.GetFiles(currentPath))
                    {
                        int    indexOfLastSlash = directoryPath.LastIndexOf("\\");
                        string fileName         = directoryPath.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(
                            new string('-', indexOfLastSlash) + fileName);
                    }

                    foreach (string directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    throw new Exception(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
Beispiel #17
0
        public static void TraverseDirectory(string path, int depth)
        {
            OutputWriter.WriteEmptyLine();
            var initialIdentation = SessionData.currentPath.Split('\\').Length;
            var subFolders        = new Queue <string>();

            subFolders.Enqueue(SessionData.currentPath);
            while (subFolders.Count != 0)
            {
                //TODO: Dequeue the folder  at the start of the queue
                var currentPath = subFolders.Dequeue();
                var identation  = currentPath.Split('\\').Length - initialIdentation;

                //TODO: Print the folder path
                OutputWriter.WriteMessageOnNewLine($"{new string('-', identation)}{currentPath}");

                //TODO: Add all it's subfolders to the end of the queue

                try
                {
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        var indexOfLastSlash = file.LastIndexOf("\\");
                        var fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash) + fileName);
                    }

                    foreach (var directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
                if (depth - initialIdentation > 0)
                {
                    break;
                }
            }
        }
Beispiel #18
0
        //this is my test class that is not part of the project
        public static void countDirectory(string path)
        {
            OutputWriter.WriteEmptyLine();
            var subFolder = new Queue <string>();

            subFolder.Enqueue(path);
            int counter = 0;

            while (subFolder.Count != 0)
            {
                string currentPath = subFolder.Dequeue();
                foreach (var dir in Directory.GetDirectories(currentPath))
                {
                    subFolder.Enqueue(dir);
                    counter++;
                }
            }

            OutputWriter.WriteMessageOnNewLine($"Total directory count: {counter}");
        }
        public static void TraverseDirectory(string path)
        {
            OutputWriter.WriteEmptyLine();
            var initialIdentation = path.Split('\\').Length;
            var subFolder         = new Queue <string>();

            subFolder.Enqueue(path);

            while (subFolder.Count != 0)
            {
                var currentPath = subFolder.Dequeue();
                var identation  = currentPath.Split('\\').Length - initialIdentation;
                OutputWriter.WriteMessageOnNewLine(string.Format($"{new string('-', identation)}{currentPath}"));

                foreach (var directoryPath in Directory.GetDirectories(currentPath))
                {
                    subFolder.Enqueue(directoryPath);
                }
            }
        }
Beispiel #20
0
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int            startDepth      = SessionData.currentPath.Split('\\').Length;
            Queue <string> pathsToTraverse = new Queue <string>();

            pathsToTraverse.Enqueue(SessionData.currentPath);

            while (pathsToTraverse.Count > 0)
            {
                var currentPath  = pathsToTraverse.Dequeue();
                var currentDepth = currentPath.Split('\\').Length - startDepth;

                if (depth - currentDepth < 0)
                {
                    break;
                }

                OutputWriter.WriteMessageOnNewLine($"{new string('-', currentDepth)}{currentPath}");

                try
                {
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        var indexOfSlash = file.LastIndexOf('\\');
                        var fileName     = file.Substring(indexOfSlash);
                        OutputWriter.WriteMessageOnNewLine(String.Format(
                                                               @"{0}{1}", new string('-', indexOfSlash), fileName));
                    }

                    foreach (string directory in Directory.GetDirectories(currentPath))
                    {
                        pathsToTraverse.Enqueue(directory);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
Beispiel #21
0
        public static void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int initialIdentation = SessionData.CurrentPath.Split('\\').Length;
            var subFolders        = new Queue <string>();

            subFolders.Enqueue(SessionData.CurrentPath);

            while (subFolders.Count != 0)
            {
                string currentPath = subFolders.Dequeue();
                int    identation  = currentPath.Split('\\').Length - initialIdentation;

                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', identation), currentPath));

                try
                {
                    foreach (string directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(directoryPath);
                    }

                    //get and write file names for current directory
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        var indexOfLastSplash = file.LastIndexOf('\\');
                        var fileName          = file.Substring(indexOfLastSplash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSplash) + fileName);
                    }
                }
                catch (System.UnauthorizedAccessException)
                {
                    OutputWriter.DisplayExeptions(ExceptionMessages.UnauthorizedAccessException);
                }

                if (depth - identation < 0)
                {
                    break;
                }
            }
        }
Beispiel #22
0
        public static void TraverseDirectorty(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int initialIndentation = SessionData.currentPath.Split('\\').Length;
            var subFolders         = new Queue <string>();

            subFolders.Enqueue(SessionData.currentPath);

            while (subFolders.Count != 0)
            {
                var currentPath = subFolders.Dequeue();
                int identation  = currentPath.Split('\\').Length - initialIndentation;
                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', identation), currentPath));

                try
                {
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        var indexOfLastSlash = file.LastIndexOf("\\");
                        var fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash) + fileName);

                        //It page 8 of 03-Document(First Part)
                        //It should be depth - identation
                        if (depth - identation < 0)
                        {
                            break;
                        }
                    }
                    foreach (var directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.WriteMessageOnNewLine(ExceptionMessages.UnauthorizedAccessException);
                }
            }
        }
Beispiel #23
0
        public static void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int initialIdentation = SessionData.currentPath.Split('\\').Length;
            Queue<string> subfolders = new Queue<string>();
            subfolders.Enqueue(SessionData.currentPath);

            while (subfolders.Count != 0)
            {
                string currentFolder = subfolders.Dequeue();
                int identation = currentFolder.Split('\\').Length - initialIdentation;
                if (depth - identation < 0)
                {
                    break;
                }
                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', identation), currentFolder));
                try
                {
                    foreach (var file in Directory.GetFiles(currentFolder))
                    {
                        int index = file.LastIndexOf("\\");
                        string fileName = file.Substring(index);
                        OutputWriter.WriteMessageOnNewLine(new string('-', index) + fileName);
                    }

                    foreach (var directory in Directory.GetDirectories(currentFolder))
                    {
                        subfolders.Enqueue(directory);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayExeption(ExeptionMessages.UnauthorizedAccessExceptionMessage);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        public static void TraverseDirectory(string path, int depth)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIdentation = path.Split('\\').Length;
            Queue <string> subFolders        = new Queue <string>();

            subFolders.Enqueue(path);

            while (subFolders.Count > 0)
            {
                var currentPath = subFolders.Dequeue();
                int identation  = currentPath.Split('\\').Length;

                if (identation - initialIdentation >= depth)
                {
                    return;
                }

                OutputWriter.WriteMessageOnNewLine($"{new string('-', identation)}{currentPath}");

                try
                {
                    foreach (string file in Directory.GetFiles(currentPath))
                    {
                        int    indexOfLastSlash = file.LastIndexOf('\\');
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine($"{new string('-', indexOfLastSlash)}{fileName}");
                    }

                    foreach (string directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolders.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
Beispiel #25
0
        public static void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int initialIdentation = 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 - initialIdentation;

                if (depth - identation < 0)
                {
                    break;
                }

                OutputWriter.WriteMessageOnNewLine($"{new string('-', identation)}{currentPath}");

                try
                {
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        int    indexOfLastSlash = file.LastIndexOf('\\');
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash) + fileName);
                    }

                    foreach (var dirPath in Directory.GetDirectories(currentPath))
                    {
                        subfolders.Enqueue(dirPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    Console.WriteLine(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }
Beispiel #26
0
        public void TraverseDirectory(string depth)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIndentation = SessionData.currentPath.Split('\\').Length;
            Queue <string> subFolders         = new Queue <string>();

            subFolders.Enqueue(SessionData.currentPath);

            while (subFolders.Count != 0)
            {
                string currentPath = subFolders.Dequeue();
                int    indentation = currentPath.Split('\\').Length - initialIndentation;

                OutputWriter.WriteMessageOnNewLine(string.Format("{0}{1}", new string('-', indentation), currentPath));

                try
                {
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        int    indexOfLastSlash = file.LastIndexOf("\\");
                        string filename         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageOnNewLine(new string('-', indexOfLastSlash) + filename);
                    }

                    var subDirectories = Directory.GetDirectories(currentPath);
                    foreach (var subDir in subDirectories)
                    {
                        subFolders.Enqueue(subDir);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayExeption(ExceptionMessages.UnauthorizedAccessExceptionMessage);
                }
            }
        }