コード例 #1
0
 public IEnumerable <string> GetFiles(string path, SearchOption searchOption, string[] extensions = null)
 {
     if (string.IsNullOrEmpty(path))
     {
         throw new ArgumentNullException(nameof(path));
     }
     if (!Directory.Exists(path))
     {
         throw new ArgumentException("Folder does not exist.", nameof(path));
     }
     DirectoryRead?.Invoke(this, new DirectoryReadEventArgs(path));
     if (extensions == null)
     {
         ExtensionsRead?.Invoke(this, new ExtensionsReadEventArgs("*.*"));
         foreach (var file in Directory.EnumerateFiles(path, "*.*", searchOption))
         {
             yield return(file);
         }
     }
     else
     {
         foreach (var extension in extensions)
         {
             ExtensionsRead?.Invoke(this, new ExtensionsReadEventArgs(extension));
             foreach (var file in Directory.EnumerateFiles(path, "*.*", searchOption)
                      .Where(s => s.ToLower().EndsWith(extension.ToLower())))
             {
                 yield return(file);
             }
         }
     }
 }
コード例 #2
0
ファイル: MtpDirectory.cs プロジェクト: oduma/Sciendo.Common
 private IEnumerable <string> GetContents(
     PortableDevice mtpDevice,
     PortableDeviceFolder mtpFolder,
     string path,
     SearchOption searchOption,
     string[] extensions = null)
 {
     if (extensions == null)
     {
         extensions = new[] { "*.*" }
     }
     ;
     foreach (var extension in extensions)
     {
         ExtensionsRead?.Invoke(this, new ExtensionsReadEventArgs(extension));
         foreach (var file in EnumerateFiles(mtpDevice, mtpFolder, path, searchOption)
                  .Where(s => s.ToLower().EndsWith(extension.ToLower()) || extension == "*.*"))
         {
             yield return(file);
         }
     }
 }