How to

parse path

Published: 25. October 2011 | Updated: 25. October 2011
License: Microsoft Public License (MS-PL)
Categories: File system
Tags: C# Text
Was this snippet helpful for you? YESYES / NONO
Get Analyzant!

Check your entire website from code to content in minutes with Analyzant, the free analysis suite.

Free download at

Import namespace

using System.IO;


string path = @"C:\Folder\file.txt";


Console.WriteLine("Directory name: {0}", Path.GetDirectoryName(path));
Console.WriteLine("File name: {0}", Path.GetFileName(path));
Console.WriteLine("File name without extension: {0}", Path.GetFileNameWithoutExtension(path));
Console.WriteLine("File extension: {0}", Path.GetExtension(path));
Console Output:

Directory name: C:\Folder
File name: file.txt
File name without extension: file
File extension: .txt
Send us feedback about this snippet »

Related Snippets: