【发布时间】:2013-08-26 03:22:33
【问题描述】:
伙计们,正如标题所说,我必须获取具有特定(用户指定)子字符串的文件夹的名称。
我有一个文本框,用户将在其中输入想要的子字符串。 我正在使用下面的代码来实现我的目标。
string name = txtNameSubstring.Text;
string[] allFiles = System.IO.Directory.GetFiles("C:\\Temp");//Change path to yours
foreach (string file in allFiles)
{
if (file.Contains(name))
{
cblFolderSelect.Items.Add(allFiles);
// MessageBox.Show("Match Found : " + file);
}
else
{
MessageBox.Show("No files found");
}
}
它不起作用。 当我触发它时,只出现消息框。 帮忙?
【问题讨论】:
-
如果您要查找文件夹,为什么要搜索文件?
标签: c# asp.net file directory substring