myVar = "D:\\mainfolder\\subf1\\subf2\\subf3\\file.txt";
How can I get file.txt
conveniently in .NET 2.0 with C#?
What I know is split with \\
and try to get the last member.
Thanks.
string fileNameOnly = Path.GetFileName("D:\\mainfolder\\subf1\\subf2\\subf3\\file.txt");
should return file.txt
Linking Path's class documentation on MSDN. Has many other convenient methods.
System.IO.Path.GetFileName(myVar);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With