public void CalculateFolderSize(Folder folder, ref long sum)
        {
            if (folder == null)
            {
                throw new ArgumentNullException("Folder cannot be null!");
            }

            for (int i = 0; i < folder.Files.Length; i++)
            {
                if (folder.Files[i] != null)
                {
                    sum += folder.Files[i].Size;
                }
            }

            for (int i = 0; i < folder.ChildFoldersCount; i++)
            {
                Folder currentFolder = folder.GetChildFolderAtIndex(i);
                CalculateFolderSize(currentFolder, ref sum);
            }
        }
        private Folder PopulateFileTree(Folder root)
        {
            string[] files = Directory.GetFiles(root.Name);
            IEnumerable<string> folders = Directory.EnumerateDirectories(root.Name);

            AddFilesToFolder(root, files);
            AddSubfoldersToFolder(root, folders);

            for (int i = 0; i < root.ChildFoldersCount; i++)
            {
                try
                {
                    root.ChildFolders[i] = PopulateFileTree(root.GetChildFolderAtIndex(i));
                }
                catch (UnauthorizedAccessException)
                {
                    Console.WriteLine("{0} cannot be accessed!", root.GetChildFolderAtIndex(i));
                }
            }

            return root;
        }
        private Folder FindFolder(Folder start, string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("Path cannot be null");
            }

            if (start.Name == path)
            {
                return start;
            }

            for (int i = 0; i < start.ChildFoldersCount; i++)
            {
                Folder currentFolder = start.GetChildFolderAtIndex(i);
                FindFolder(currentFolder, path);
            }

            throw new ArgumentException("Folder not found in tree hierarchy!");
        }