![C# Path.GetDirectoryName method code example 1 Path.GetDirectoryName method code example](https://znlive.com/wp-content/uploads/2021/03/coding-1024x683.jpg)
C# Path.GetDirectoryName method code example. This article summarizes the typical usage code examples of the System.IO.Path.GetDirectoryName method in C#. If you are suffering from the following question: The specific usage of the C# Path.GetDirectoryName method? How to use C# Path.GetDirectoryName? C# Path.GetDirectoryName use example?
Congratulations, the method code examples selected here may help you. You can also learn more about the usage example of the class System.IO.Path where the method is located.
![C# Path.GetDirectoryName method code example 2 How to publish guest posts on znlive](https://znlive.com/wp-content/uploads/2021/03/How-to-publish-guest-posts-on-znlive-1024x621.jpg)
Path.GetDirectoryName method code example
string filePath = @"C:\MyDir\MySubDir\znlive.com.ext"; string directoryName; int i = 0; while (filePath != null) { directoryName = Path.GetDirectoryName(filePath); Console.WriteLine("GetDirectoryName('{0}') returns '{1}'", filePath, directoryName); filePath = directoryName; if (i == 1) { filePath = directoryName + @"\"; // this will preserve the previous path } i++; }
Path.GetDirectoryName method code example
Developer NET developer, project name: System.IO, code lines: 16, code source: Path.GetDirectoryName
Output:
GetDirectoryName('C:\MyDir\MySubDir\znlive.com.ext') returns 'C:\MyDir\MySubDir' GetDirectoryName('C:\MyDir\MySubDir') returns 'C:\MyDir' GetDirectoryName('C:\MyDir\') returns 'C:\MyDir' GetDirectoryName('C:\MyDir') returns 'C:\' GetDirectoryName('C:\') returns ''
![C# Path.GetDirectoryName method code example 3 publish guest posts on znlive](https://znlive.com/wp-content/uploads/2021/03/publish-guest-posts-on-znlive-1024x605.jpg)