What's the fast way to get the file name?
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);
精彩评论