开发者

What's the fast way to get the file name?

开发者 https://www.devze.com 2023-04-05 01:58 出处:网络
myVar = \"D:\\\\mainfolder\\\\subf1\\\\开发者_开发知识库subf2\\\\subf3\\\\file.txt\"; How can I get file.txt conveniently in .NET 2.0 with C#?
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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号