Extensions GetFileNameWithoutExtension will return the entire file name if there's no extension on the file.Path.GetDirectoryName returns the entire string except the file name and the slash before it.
Syntax
When specifying paths in C# programs, we must use two backslashes "\\" unless we use the verbatim string syntax. A verbatim string uses the prefix character "@". Only one backslash is needed in this literal syntax.
using System; using System.IO; class Program { static void Main() { // ... Verbatim string syntax. string value = @"C:\directory\word.txt"; Console.WriteLine(Path.GetFileName(value)); } }
OutPut
word.txt
0 comments
Post a Comment