#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