public IEnumerable <FileInfo> EnumerateMatchingFiles(string location, FileEnumeratorCriteria fileHandlerOptions) { return(new DirectoryInfo(location) .EnumerateFiles("*", fileHandlerOptions.IncludeSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) .Where(x => _fileFilterer.Filter(new FileData { FileName = x.Name, Extension = x.Extension, FullPath = x.FullName, ByteSize = x.Length }, fileHandlerOptions))); }
public bool Filter(FileData fileInfo, FileEnumeratorCriteria options) { if (options.Extensions != null && options.Extensions.All(extension => extension != fileInfo.Extension)) { return(false); } if (options.MinByteSize != null && fileInfo.ByteSize < options.MinByteSize) { return(false); } if (options.MaxByteSize != null && fileInfo.ByteSize > options.MaxByteSize) { return(false); } if (options.Exclude != null && options.Exclude.Any(excludeTerm => fileInfo.FileName.Contains(excludeTerm))) { return(false); } return(true); }
public FileInfo GetRandomFile(string location, FileEnumeratorCriteria fileHandlerOptions) { return(_fileEnumerator .EnumerateMatchingFiles(location, fileHandlerOptions) .Random()); }