public void TraverseFolder(DirectoryInfo dirInfo)
        {
            string directoryName = dirInfo.Name,
                   directoryPath = dirInfo.FullName;

            Dictionary <string, List <FileInfo> > directoryFiles = helper.GetDirectoryFiles(dirInfo);

            WriteDirectoryToDocument(directoryName, directoryPath);
            WriteFileInformation(directoryFiles);

            foreach (var dir in dirInfo.GetDirectories())
            {
                try
                {
                    TraverseFolder(dir);
                }
                catch (UnauthorizedAccessException ex)
                {
                    LogUnauthorizedAccess(dir.FullName, ex);
                }
                catch (PathTooLongException ex)
                {
                    LogPathToLoog(dir.FullName, ex);
                }
            }

            CloseCurrentDirectory(directoryName);
        }
Exemplo n.º 2
0
        private static void PrintFilesWhere(
            DirectoryInfo dir, string extension, string indent = null)
        {
            if (string.IsNullOrEmpty(indent))
            {
                indent = string.Empty;
            }

            var files = helper.GetDirectoryFiles(dir)
                        .Where(ext => ext.Key.Equals(extension, StringComparison.OrdinalIgnoreCase))
                        .SelectMany(ext => ext.Value);

            if (files.Any())
            {
                // Console.ReadKey(true);
                helper.ConsoleMio.WriteLine(
                    "{0}Folder: {1}", ConsoleColor.DarkRed, indent, dir.Name);

                indent = "\t" + indent;

                foreach (var file in files)
                {
                    helper.ConsoleMio.WriteLine(
                        "{0}--> {1} ({2}kb)",
                        ConsoleColor.DarkCyan,
                        indent,
                        file.Name,
                        helper.ConvertFileLength(file.Length, FileLength.KB));
                }
            }

            try
            {
                var folders = dir.GetDirectories();

                foreach (var folder in folders)
                {
                    PrintFilesWhere(folder, extension, indent);
                }
            }
            catch (UnauthorizedAccessException)
            {
                // Ups... Skip this one
            }
        }