DirectoryInfo.GetFiles Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Returns a file list from the current directory.

Namespace:   System.IO
Assembly:  mscorlib (in mscorlib.dll)

member GetFiles : unit -> FileInfo[]

Return Value

Type: System.IO.FileInfo[]

An array of type FileInfo.

Exception Condition

The path is invalid, such as being on an unmapped drive.

The EnumerateFiles and GetFiles methods differ as follows:

  • When you use EnumerateFiles, you can start enumerating the collection of FileInfo objects before the whole collection is returned.

  • When you use GetFiles, you must wait for the whole array of FileInfo objects to be returned before you can access the array.

Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.

If there are no files in the DirectoryInfo, this method returns an empty array.

The order of the returned file names is not guaranteed; use the Sort method if a specific sort order is required.

This method pre-populates the values of the following FileInfo properties:

The following example shows how to get a list of files from a directory by using different search options. The example assumes a directory that has files named log1.txt, log2.txt, test1.txt, test2.txt, test3.txt, and a subdirectory that has a file named SubFile.txt.

No code example is currently available or this language may not be supported.


for reading directories. Associated enumeration: FileIOPermissionAccess.Read

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top