Use of the Directory.GetFiles () function in C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.