如何从目录中获取文件名,而不是整个路径
我使用下面的方法来获取文件名..
但它返回整个路径….现在我不想得到整个路径..
我只想要文件名而不是整个路径……
我怎么能得到只有文件名而不是整个路径
path = c: docs doc backup-23444444.zip
string[] filenames = Directory.GetFiles(targetdirectory,"backup-*.zip"); foreach (string filename in filenames) { }
任何人都会对此有所帮助…..
非常感谢…
您可以使用GetFileName方法仅提取没有路径的文件名:
string filenameWithoutPath = Path.GetFileName(filename);
System.IO.Path
是你的朋友:
var filenames = from fullFilename in Directory.EnumerateFiles(targetdirectory,"backup-*.zip") select Path.GetFileName(fullFilename); foreach (string filename in filenames) { // ... }
尝试Path.GetFileName(filename)方法
上述就是C#学习教程:如何从目录中获取文件名,而不是整个路径分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
You can use this, it will give you all file's name without Extension List lstAllFileName = (from itemFile in dir.GetFiles() select Path.GetFileNameWithoutExtension(itemFile.FullName)).Cast ().ToList();
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/955058.html