Gets a list of all files in the specified directory and subdirectories

Source: Internet
Author: User

#region get a list of all files in the specified directory and subdirectories
<summary>
Gets a list of all files in the specified directory and subdirectories
</summary>
<param name= "DirectoryPath" > The absolute path of the specified directory </param>
<param name= "searchpattern" > Pattern string, "*" stands for 0 or n characters, "?" Represents a 1 character.
Example: "Log*.xml" means searching for all XML files that begin with Log. </param>
<param name= "Issearchchild" > whether to search subdirectories </param>
public static string[] GetFileNames (String directorypath, String searchpattern, bool issearchchild)
{
Throws an exception if the directory does not exist
if (! Isexistdirectory (DirectoryPath))
{
throw new FileNotFoundException ();
}


Try
{
if (issearchchild)
{
Return Directory.GetFiles (DirectoryPath, searchpattern, searchoption.alldirectories);
}
Else
{
Return Directory.GetFiles (DirectoryPath, searchpattern, searchoption.topdirectoryonly);
}
}
catch (IOException ex)
{
Throw ex;
}
}
#endregion

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Gets a list of all files in the specified directory and subdirectories

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.