c#没有文件扩展名的搜索结果

Jur*_*nto 1 c# search winforms

我需要在列表框中的搜索结果显示中隐藏文件扩展名(.jpg,.exe).有人可以帮我弄这个吗?这是我的代码.我有文本框,按钮和列表框.

button1代码:此代码在指定的路径上搜索我的文本框上的单词并在listbox1上显示:

private void button1_Click(object sender, EventArgs e)
{
    x = 0;
    var path = "C:\\Users\\john\\Desktop\\FLASH\\SEARCH";
    listBox1.DataSource = Directory.GetFiles(path, "*" + textBox1.Text + "*")
        .Select(f => Path.GetFileName(f)).ToList();
}
Run Code Online (Sandbox Code Playgroud)

listbox1代码:此代码在点击时运行搜索结果:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    var fileName = listBox1.SelectedItem as string;
    if (fileName != null)
    {
        var path = Path.Combine("C:\\Users\\thesis\\Desktop\\THESIS\\FLASH\\SEARCH", fileName);

        if (x != 0)
        {
            Process.Start(path);
        } 
    }
    x += 1;
}
Run Code Online (Sandbox Code Playgroud)

使用此代码,我的输出如下:"result.exe""result.jpg".我需要的输出是这样的:"结果","输出".

alg*_*eat 8

使用 GetFileNameWithoutExtension

private void button1_Click(object sender, EventArgs e)
        {
            x = 0;
            var path = "C:\\Users\\john\\Desktop\\FLASH\\SEARCH";
            listBox1.DataSource = Directory.GetFiles(path, "*" + textBox1.Text + "*")
                               .Select(f => Path.GetFileNameWithoutExtension(f))
                               .ToList();
        }
Run Code Online (Sandbox Code Playgroud)