Пример #1
0
        private static void BuildDirectoryTree(CustomFolder rootDirectory)
        {
            try
            {
                var childDirectories = Directory.GetDirectories(rootDirectory.Name);
                foreach (string directory in childDirectories)
                {
                    rootDirectory.ChildDirectories.Add(new CustomFolder(directory));
                }
            }
            catch (UnauthorizedAccessException)
            {
                // Handle directories we dont have access to.
            }

            foreach (var childDirectory in rootDirectory.ChildDirectories)
            {
                CustomFolder.BuildDirectoryTree(childDirectory);
            }

            try
            {
                var files = Directory.GetFiles(rootDirectory.Name);
                foreach (string file in files)
                {
                    var info = new FileInfo(file);
                    rootDirectory.Files.Add(new CustomFile(file, info.Length));
                }
            }
            catch (UnauthorizedAccessException)
            {
                // Handle files we dont have access to.
            }
        }
Пример #2
0
        public static CustomFolder GetDirectory(string path)
        {
            var directory = new CustomFolder(path);

            CustomFolder.BuildDirectoryTree(directory);
            return(directory);
        }
Пример #3
0
        private static void BuildDirectoryTree(CustomFolder rootDirectory)
        {
            try
            {
                var childDirectories = Directory.GetDirectories(rootDirectory.Name);
                foreach (string directory in childDirectories)
                {
                    rootDirectory.ChildDirectories.Add(new CustomFolder(directory));
                }
            }
            catch (UnauthorizedAccessException)
            {
                // Handle directories we dont have access to.
            }

            foreach (var childDirectory in rootDirectory.ChildDirectories)
            {
                CustomFolder.BuildDirectoryTree(childDirectory);
            }

            try
            {
                var files = Directory.GetFiles(rootDirectory.Name);
                foreach (string file in files)
                {
                    var info = new FileInfo(file);
                    rootDirectory.Files.Add(new CustomFile(file, info.Length));
                }
            }
            catch (UnauthorizedAccessException)
            {
                // Handle files we dont have access to.
            }
        }
Пример #4
0
        public static void Main()
        {
            var path      = @"C:\Windows";
            var directory = CustomFolder.GetDirectory(path);

            Console.WriteLine(path + "size in bytes: " + directory.GetMemorySizeInBytes());
        }
Пример #5
0
 public static CustomFolder GetDirectory(string path)
 {
     var directory = new CustomFolder(path);
     CustomFolder.BuildDirectoryTree(directory);
     return directory;
 }