Exemple #1
0
        public IList <ImageFile> GetImageFileListFromFolder(string folderPath)
        {
            IList <ImageFile> result = new List <ImageFile>();

            try
            {
                //search all subfolders for files and return new FileInfo object
                var directoryFiles = Directory
                                     .EnumerateFiles(folderPath, "*", SearchOption.AllDirectories)
                                     .Where(f => _imageExts.Any(x => f.ToLower().EndsWith(x.ToLower())))
                                     .Select(x => new FileInfo(x))
                ;

                foreach (var file in directoryFiles)
                {
                    var theImage = _imageManager.CreateBitmapFromFilePath(file.FullName);

                    result.Add(new ImageFile()
                    {
                        Name     = file.Name,
                        FullPath = file.DirectoryName,
                        Image    = theImage
                    });
                }

                return(result);
            }
            catch (Exception e)
            {
                _consolePrinter.PrintError("There was an error reading the folder", e);

                throw;
            }
        }