我正在搜索文件。并且根據(jù)我在 textBox2 中鍵入的擴(kuò)展名,我想在其中搜索文件類型。例如,如果我在 textBox2 .txt 中鍵入,它將搜索所有文本文件。但我不想輸入 .cs 或 .txt 我只想輸入 cs 或 txtstring restrictedFile = ""; List<string> restrictedFiles = new List<string>(); int numberofrestrictedFiles = 0; int numberoffiles = 0; IEnumerable<string> SearchAccessibleFilesNoDistinct(string root, List<string> files,BackgroundWorker worker, DoWorkEventArgs e) { _busy.WaitOne(); if (files == null) files = new List<string>(); if (Directory.Exists(root)) { foreach (var file in Directory.EnumerateFiles(root)) { if (worker.CancellationPending == true) { e.Cancel = true; return files; } restrictedFile = file; string ext = Path.GetExtension(file); if (!files.Contains(file) && ext == textBox2.Text) { files.Add(file); } numberoffiles++; label24.Invoke((MethodInvoker)delegate { label24.Text = numberoffiles.ToString(); label24.Visible = true; }); } foreach (var subDir in Directory.EnumerateDirectories(root)) { if (worker.CancellationPending == true) { e.Cancel = true; return files; } try { SearchAccessibleFilesNoDistinct(subDir, files,worker, e); }在這部分,我獲取文件擴(kuò)展名并檢查 textBox2 中的文件擴(kuò)展名是否相同。但是由于文件擴(kuò)展名是 .txt 或 .cs 或 .gif,我還必須在 textBox2 中輸入“.”。相反,我只想輸入 cs gif txt....另一個(gè)子問題,我怎樣才能讓它在所有文件擴(kuò)展名中搜索?例如,如果我在 textBox2 中鍵入他的字符串 ALL 或 maybe 。所以它會(huì)搜索所有的擴(kuò)展。
如何將文件擴(kuò)展名與文本框中鍵入的內(nèi)容進(jìn)行比較,而不是先點(diǎn)?
揚(yáng)帆大魚
2022-11-22 16:25:24