public void GenerateFoldersTestSubFolders()
 {
     Folder sample = new Folder("..\\..\\SampleDir");
     DirectoryStructureDemo.GenerateFolders(sample);
     int expectedFolders = 2;
     int actualFolders = sample.ChildFolders.Count;
     Assert.AreEqual(expectedFolders, actualFolders);
 }
 public void GenerateFoldersTestFileSizeOneDir()
 {
     Folder sample = new Folder("..\\..\\SampleDir");
     DirectoryStructureDemo.GenerateFolders(sample);
     long expectedFileSize = 33;
     long actualFileSize = sample.ChildFolders[1].GetSize();
     Assert.AreEqual(expectedFileSize, actualFileSize);
 }
 public void GenerateFoldersTestFiles()
 {
     Folder sample = new Folder("..\\..\\SampleDir");
     DirectoryStructureDemo.GenerateFolders(sample);
     int expectedFiles = 1;
     int actualFiles = sample.Files.Count;
     Assert.AreEqual(expectedFiles, actualFiles);
 }
        /// <summary>
        /// Mains this instance.
        /// </summary>
        public static void Main()
        {
            // Console.WriteLine("The folder is big. Wait a moment...");
            Folder root = new Folder(ROOT_DIRECTORY);
            GenerateFolders(root);

            Console.WriteLine("Folder: " + root.Name);
            // Console.WriteLine(errorLog);
            Console.WriteLine("Size in bytes: " + root.GetSize());
        }
        private static bool CheckXMLFileExists(string fileName, Folder folder)
        {
            bool xmlFileExists = false;

            foreach (var file in folder.Files)
            {
                if (file.Path == fileName)
                {
                    xmlFileExists = true;
                    break;
                }
            }

            return xmlFileExists;
        }
Exemple #6
0
        /// <summary>
        /// Gets the size of the folder.
        /// </summary>
        /// <returns>The size of the folder in bytes.</returns>
        public static long PrintFolderFilesInfo(Folder folder)
        {
            long sum = 0;

            // Get files sizes for current directory.
            foreach (var file in folder.Files)
            {
                PrintFileData(file.Path);
            }

            // Get childs folders size recuresively.
            foreach (var childFolder in folder.ChildFolders)
            {
                PrintFolderFilesInfo(childFolder);
            }

            return sum;
        }
Exemple #7
0
        /// <summary>
        /// Generates the folders.
        /// </summary>
        /// <param name="folder">The folder.</param>
        public static void GenerateFolders(Folder folder)
        {
            try
            {
                var dirs = Directory.GetDirectories(folder.Path);
                var fileNames = Directory.GetFiles(folder.Path);
                var files = GenerateFiles(fileNames);
                folder.Files.AddRange(files);

                // Walk recuresively through all sub folders.
                foreach (var dir in dirs)
                {
                    Folder currentFolder = new Folder(dir);
                    folder.ChildFolders.Add(currentFolder);
                    GenerateFolders(currentFolder);
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                errorLog.AppendLine(ex.Message);
                return;
            }
        }
 /// <summary>
 /// Initializes the root directory.
 /// </summary>
 private static void InitializeRootDirectory()
 {
     ROOT = new Folder(TEMP_DIRECTORY);
     GenerateFolders(ROOT);
 }
 public void FolderObjectCreation()
 {
     Folder sample = new Folder("..\\..\\SampleDir");
     Assert.IsNotNull(sample);
 }