Author : Admin

How do I get the directory from a file's full path in C#?


In C#, you can use the GetDirectoryName() method of Path Class to get directory path without filename.

string fileNameWithPath = @"c:\users\gurukultree\documents\demo.txt";
string directoryPathOnly = Path.GetDirectoryName(fileNameWithPath );

Output:
c:\users\gurukultree\documents

Here is the method GetDirectoryName() which return the Full Directory Path without the FileName.