C# Directory.GetDirectories searchPattern regex



  • Using:

    string[] directoryList = Directory.GetDirectories(path, searchP);
    

    The question is, how do you use regular expression as a searchP parameter or something that would help remove the mask catalogues? @"!_*"



  • You may use the following approach:

    var directoryList = new DirectoryInfo(path)
        .EnumerateDirectories()
        .Where(dirInfo => Regex.IsMatch(dirInfo.Name, searchPattern))
        .ToArray();
    

    We're filtering the mask files with LINQ and standard Regex.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2