示例#1
0
 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)));
 }
示例#2
0
        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);
        }
示例#3
0
 public FileInfo GetRandomFile(string location, FileEnumeratorCriteria fileHandlerOptions)
 {
     return(_fileEnumerator
            .EnumerateMatchingFiles(location, fileHandlerOptions)
            .Random());
 }