Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

FileInfo.DirectoryName Property

Definition

Namespace:
System.IO
Assemblies:
mscorlib.dll, System.IO.FileSystem.dll
Assemblies:
netstandard.dll, System.Runtime.dll
Assemblies:
netstandard.dll, System.IO.FileSystem.dll
Assemblies:
netstandard.dll, System.IO.FileSystem.dll, System.Runtime.dll
Assembly:
System.IO.FileSystem.dll
Assembly:
mscorlib.dll
Assembly:
netstandard.dll
Source:
FileInfo.cs
Source:
FileInfo.cs
Source:
FileInfo.cs
Source:
FileInfo.cs
Source:
FileInfo.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Gets a string representing the directory's full path.

public:
 property System::String ^ DirectoryName { System::String ^ get(); };
public string DirectoryName { get; }
public string? DirectoryName { get; }
member this.DirectoryName : string
Public ReadOnly Property DirectoryName As String

Property Value

A string representing the directory's full path.

Exceptions

null was passed in for the directory name.

The fully qualified path name exceeds the system-defined maximum length.

The caller does not have the required permission.

Examples

The following example retrieves the full path of the specified file.

string fileName = @"C:\TMP\log.txt";
FileInfo fileInfo = new FileInfo(fileName);
if (!fileInfo.Exists)
{
 return;
}

Console.WriteLine("{0} has a directoryName of {1}",
 fileName, fileInfo.DirectoryName);
/* This code produces output similar to the following,
 * though actual results may vary by machine:
 *
 * C:\TMP\log.txt has a directory name of C:\TMP
 */

Remarks

To get the parent directory as a DirectoryInfo object, use the Directory property.

When first called, FileInfo calls Refresh and caches information about the file. On subsequent calls, you must call Refresh to get the latest copy of the information.

Applies to

See also


Feedback

Was this page helpful?