Directory.GetFileSystemEntries Method (String, String)
Returns an array of file system entries matching the specified search criteria.
Assembly: mscorlib (in mscorlib.dll)
public static function GetFileSystemEntries( path : String, searchPattern : String ) : String
- Type: System.String
The path to be searched.
- Type: System.String
The search string to match against the names of files in path. The searchPattern parameter cannot end in two periods ("..") or contain two periods ("..") followed by DirectorySeparatorChar or AltDirectorySeparatorChar, nor can it contain any of the characters in InvalidPathChars.
Return ValueType: System.String
A String array of file system entries matching the search criteria.
The caller does not have the required permission.
path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
searchPattern does not contain a valid pattern.
path or searchPattern is a null reference (Nothing in Visual Basic).
The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.
path is a file name.
The specified path is invalid (for example, it is on an unmapped drive).
The following wildcard specifiers are permitted in searchPattern.
Zero or more characters.
Exactly one character.
Characters other than the wildcard specifiers represent themselves. For example, the searchPattern string "*t" searches for all names in path ending with the letter "t". The searchPattern string "s*" searches for all names in path beginning with the letter "s".
The matching behavior of searchPattern when the extension is exactly three characters long is different from when the extension is more than three characters long. A searchPattern of exactly three characters returns files having an extension of three or more characters. A searchPattern of one, two, or more than three characters returns only files having extensions of exactly that length.
The following list shows the behavior of different lengths for the searchPattern parameter:
"*.abc" returns files having an extension of.abc,.abcd,.abcde,.abcdef, and so on.
"*.abcd" returns only files having an extension of.abcd.
"*.abcde" returns only files having an extension of.abcde.
"*.abcdef" returns only files having an extension of.abcdef.
The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see GetCurrentDirectory.
The path parameter is not case-sensitive.
For a list of common I/O tasks, see Common I/O Tasks.
The following example uses the GetFileSystemEntries method to fill an array of strings with the names of all files matching a user-specified filter in a specific location and prints each string in the array to the console. The example is configured to catch all errors common to this method.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.