Reputation: 265
In my c# code, I am reading file name to a variable and they could be like C:\users\documetnts\test.bin but, how can I get rid of the whole path i just want to store file name test.bin not the whole path.
How can I do this?
Upvotes: 0
Views: 44
Reputation: 54532
Use the Path.GetFileName
Method from the Path
Class in the System.IO Namespace:
class Program
{
static void Main(string[] args)
{
string path = @"C:\users\documetnts\test.bin";
Console.WriteLine( Path.GetFileName(path));
Console.ReadLine();
}
}
Upvotes: 2