Ejemplo n.º 1
0
        public static void SaveData(DirectoryInfo directory, Folder folder)
        {
            try
            {
                FileInfo[] files = directory.GetFiles();
                SaveFiles(files, folder.Files);
                DirectoryInfo[] directories = directory.GetDirectories();
                SaveFolders(directories, folder.ChildFolders);

                foreach (var dir in directory.GetDirectories())
                {
                    foreach (var childFolder in folder.ChildFolders)
                    {
                        if (dir.Name == childFolder.Name)
                        {
                            SaveData(dir, childFolder);
                        }
                    }
                }
            }

            catch (UnauthorizedAccessException)
            {
            }
        }
Ejemplo n.º 2
0
 private static void SaveFolders(DirectoryInfo[] directories, List<Folder> subFolders)
 {
     foreach (var directory in directories)
     {
         Folder currentFolder = new Folder(directory.Name);
         subFolders.Add(currentFolder);
     }
 }
Ejemplo n.º 3
0
 public static void Main()
 {
     string path = @"E:\Pictures";
     DirectoryInfo directory = new DirectoryInfo(path);
     Folder folder = new Folder(directory.Name);
     SaveData(directory, folder);
     Console.WriteLine(folder.GetFilesSize());
 }
Ejemplo n.º 4
0
 private void CalculateChildrenFilesSize(Folder folder)
 {
     foreach (var childFolder in folder.ChildFolders)
     {
         filesSize += GetSize(childFolder);
         CalculateChildrenFilesSize(childFolder);
     }
 }
Ejemplo n.º 5
0
        private BigInteger GetSize(Folder folder)
        {
            BigInteger sum = 0;
            foreach (var file in folder.Files)
            {
                sum += file.Size;
            }

            return sum;
        }