How can recursively search directories with multiple wildcards?

前端 未结 3 637
栀梦
栀梦 2021-01-22 00:12

Using C# (.NET), how can I search a file system given a directory search mask like this: (?)

\\\\server\\Scanner\\images\\*Images\\*\\*_*

For e

3条回答
  •  灰色年华
    2021-01-22 00:34

    Like this:

    Top Level Directories:

      //get Top level
       string[] TopLevel = Directory.GetDirectories(path);
    

    And then you will have to do a resursive function of this folders using wildcard pattern, for example:

     // Only get subdirectories that begin with the letter "p." 
                string pattern = "p*";
                string[] dirs = folder.GetDirectories(path, pattern);
    

    I suggest you play with wildcards to get the array output and you will figure out which is the best way, if using resursive function or directly quering paths.

提交回复
热议问题