如何在c#中获取文件名? [英] How to get file name in c#?
本文介绍了如何在c#中获取文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在获取系统中存在的文件的完整路径。但我只想要带扩展名的文件名..任何正文告诉我代码..
I am getting full path of a file which is present in the system. But I want only the file name with extension.. Any body tell me the code..
推荐答案
使用Path.GetFileName。此外,这是一个很容易谷歌找到你自己,这样你就不必等待别人。
Path.GetFileName方法 [ ^ ]
Use Path.GetFileName. Also, this is an easy thing to google for to find yourself so that you do not have to wait on others.
Path.GetFileName Method[^]
请参阅以下代码:
See the following code:
string a = "C:\\example.txt";
string b = Path.GetFileName(a);
那么<$ c的值$ c> b 是example.txt。使用 Path.GetFileNameWithoutExtension
也可以删除扩展名。
注意:别忘了添加使用System.IO;
使用此代码。
Then the value of b
is "example.txt". Use Path.GetFileNameWithoutExtension
to remove the extension also.
Note: Don't forget to add using System.IO;
to use this code.
使用System.IO.Path.GetFileName(fullfilepath)
获取您想要获得的唯一FileName
。
UseSystem.IO.Path.GetFileName(fullfilepath)
to get the onlyFileName
that you want to get .
这篇关于如何在c#中获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文