Ejemplo n.º 1
0
        private static void TraverseDfs(DirectoryInfo directory, CustomFolder customFolder)
        {
            try
            {
                var files = directory.GetFiles();

                foreach (var newCustomFile in files.Select(file => new CustomFile(file.Name, file.Length)))
                {
                    customFolder.Files.Add(newCustomFile);
                }

                foreach (var dir in directory.GetDirectories())
                {
                    var newCustomFolder = new CustomFolder(dir.Name);

                    TraverseDfs(dir, customFolder);

                    customFolder.Folders.Add(newCustomFolder);
                }
            }
            catch (UnauthorizedAccessException)
            {
                // Don't bother not accessed files
                return;
            }
        }
Ejemplo n.º 2
0
 private static void Main()
 {
     Console.WriteLine("If this takes too long to calculate pik a small folder");
     var customFolder = new CustomFolder("CustomFolder");
     //TraverseDfs(new DirectoryInfo(@"C:\Temp"), customFolder);
     TraverseDfs(new DirectoryInfo(@"C:\Windows"), customFolder);
     Console.WriteLine("Total size: " + customFolder.GetSize());
 }