Esempio n. 1
0
        private static void Main()
        {
            string sourceDirectory = @"C:\WINDOWS";

            DirectoryInfo startDirectoryInfo = new DirectoryInfo(sourceDirectory);

            //IList<string> collectedFiles = new List<string>();

            //collectedFiles = WalkDirectoryTree(startDirectoryInfo, collectedFiles);

            //foreach (var fileName in collectedFiles)
            //{
            //    Console.WriteLine(fileName);
            //}

            //Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

            //foreach (var exeption in logs)
            //{
            //    Console.WriteLine(exeption);
            //}

            var cDirectoryFolderTree = new Folder(sourceDirectory);
            cDirectoryFolderTree = CreateFolderTree(cDirectoryFolderTree);
            Console.WriteLine("Done!");

            var windowsFolderSize = cDirectoryFolderTree.FolderSize();
            Console.WriteLine("The size of Windows folder on this computer is {0:N} bytes", windowsFolderSize);
        }
Esempio n. 2
0
        private static Folder CreateFolderTree(Folder root)
        {
            DirectoryInfo startDirectoryInfo = new DirectoryInfo(root.Name);

            try
            {
                var currentFiles = startDirectoryInfo.GetFiles();
                foreach (var file in currentFiles)
                {
                    var currentFile = new File(file.Name, file.Length);
                    root.AddFile(currentFile);
                }

                var currentSubdirectories = startDirectoryInfo.GetDirectories();

                foreach (var directory in currentSubdirectories)
                {
                    var currentSubdirectory = new Folder(directory.FullName);
                    root.AddFolder(currentSubdirectory);
                    CreateFolderTree(currentSubdirectory);
                }
            }
            catch (Exception e)
            {
                logs.Add(e.Message);
            }

            Console.Write(".");

            return root;
        }
Esempio n. 3
0
 public void AddFolder(Folder nestedFolder)
 {
     this.folders.Add(nestedFolder);
 }
Esempio n. 4
0
 public void AddFolder(Folder nestedFolder)
 {
     this.folders.Add(nestedFolder);
 }