获取没有扩展名的文件名。 [英] get file name without extension.

查看:80
本文介绍了获取没有扩展名的文件名。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继承我的代码。



Heres my code.

DirectoryInfo di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.SendTo));

Foreach(fileinfo fi in di.getfiles())
{
ToolstripCombobox1.items.add(fi.name);
}



多数民众赞成吧。正如标题所示,我想将该文件夹中的所有文件添加到组合框中,但没有文件扩展名。



谢谢。


Thats it. As the title indicates, i want to add all the files in that folder to the combobox, but without the file extension.

Thanks.

推荐答案

您需要: http:// msdn。 microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension [ ^ ]

You need this: http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension[^]
ToolstripCombobox1.items.add(Path.GetFileNameWithoutExtension(fi.name));


IT可能会帮到你,



IT might help you,

private void PopulateToolStripComboBox()
{
    DirectoryInfo di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.SendTo));
    toolStripComboBox1.Items.AddRange(di.GetFiles().Select(file => Path.GetFileNameWithoutExtension(file.Name)).ToArray());
}





如需进一步参考,



列表< t> .AddRange [ ^ ]

它如何在C#中工作? - 第3部分(C#Linq详细介绍) [ ^ ]



希望有所帮助:)



For further ref,

List<t>.AddRange[^]
How does it work in C#? - Part 3 (C# Linq in detail)[^]

Hope it helps :)


使用GetFileNameWithoutExtension。不需要子串:)
Use GetFileNameWithoutExtension. No substrings needed :)


这篇关于获取没有扩展名的文件名。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆