How to

get directory of a file

Published: 9. October 2011 | Updated: 9. October 2011
License: Microsoft Public License (MS-PL)
Categories: File system » Directories
Tags: C# File System
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.IO;

Code

string path = @"C:\test\abc.txt";
            
var directoryName = Path.GetDirectoryName(path);

Console.WriteLine(directoryName);
Console Output:
C:\test
Send us feedback about this snippet »



Related Snippets: