C# in directory.getfiles (string path , string searchpattern, SearchOption searchoption )
Get All files in the path directory
Note: The Red font section is an optional parameter
Parameters
- Path
-
The relative or absolute path of the directory to search for. This string is case insensitive.
-
- Searchpattern
-
The search string to match the file name in path . This parameter can contain a combination of a valid text path and a wildcard character (* and?) (see Remarks), but regular expressions are not supported.
searchpattern can be a combination of text and wildcard characters, but regular expressions are not supported. The following wildcard specifier searchpattern is allowed.
Wildcard specifier |
The |
* (asterisk) |
0 or more characters at that location. |
? (question mark) |
0 or one character at that position. |
-
- Details can be found in: https://msdn.microsoft.com/zh-cn/library/ms143316 (v=vs.110). aspx
-
- after I test found that:
-
- "*.mat" can search for files in format "Box.mat", "BOX.MAT1", but cannot search for file "Box.mat.meta"
-
-
- SearchOption
-
One of the enumeration values that specifies whether the search operation should contain all subdirectories or only the current directory.
The code is as follows:
using System; using System.Runtime.InteropServices; namespace system.io{[ComVisible (truepublicenum searchoption { Topdirectoryonly, alldirectories}}
Searchoption.topdirectoryonly default option, contains only the current directory
Searchoption.alldirectories contains all subdirectories
return value type:system.string[]
An array of the full names (including paths) of the files in the specified directory that match the specified search pattern and options, or an empty array if no files are found.
1.path uses relative paths
String path = "Assets/model";
string[] files = directory.getfiles (path);
Available through Directory. GetCurrentDirectory () to view the current path.
2,path using absolute path
String path = "D:/unitydemo/assets/model"
string[] files = directory.getfiles (path)
Use of the Directory.GetFiles () function in C #