Exemplo n.º 1
0
        /// <summary>
        /// Method load all files from folder with specyfied extension
        /// </summary>
        /// <param name="filesCollection"></param>
        /// <param name="dir"></param>
        /// <param name="searchPattern"></param>
        private void GetFilesFromFolder(List <FileProperties> filesCollection, DirectoryInfo dir, string searchPattern, string dirName)
        {
            filesCollection.Add(new FileProperties(dir.Name));

            // get list of files
            try
            {
                foreach (FileInfo f in dir.GetFiles(searchPattern))
                {
                    if (_extManager.Extensions.Contains(f.Extension))
                    {
                        // Get information about files
                        filesCollection.Last().children.Add(new FileProperties(f, dirName));
                        filesCollection.Last().children.Last().fileData.AddRange(_fileManager.LoadAndReadFile(f.FullName));
                    }
                }
            }
            catch (Exception ex)
            {
                LogsManager.SaveErrorToLogFile(ex.Message);
            }

            // process each directory
            // If I have been able to see the files in the directory I should also be able
            // to look at its directories so I dont think I should place this in a try catch block
            foreach (DirectoryInfo d in dir.GetDirectories())
            {
                GetFilesFromFolder(filesCollection.Last().children, d, searchPattern, dirName);
            }
        }