C# 4.0 如果我们只知道文件名的一部分,如何读取完整的文件名,例如,从文件夹中启动XYZ \--.txt

C# 4.0 如果我们只知道文件名的一部分,如何读取完整的文件名,例如,从文件夹中启动XYZ \--.txt,c#-4.0,C# 4.0,如何从文件夹中读取所有相似的文件名。C:\Records文件夹中的文件名,如“Record_*.”.txt。例如,我的文件名以Record_uux.txt开头。所以这里我们只知道文件名的第一部分 这是我试过的,但不起作用 string path =ConfigurationManager.AppSettings["LogDir"]; string[] files = Directory.GetFiles("C:\Records", "Record_*" + ".txt", Sea

如何从文件夹中读取所有相似的文件名。C:\Records文件夹中的文件名,如“Record_*.”.txt。例如,我的文件名以Record_uux.txt开头。所以这里我们只知道文件名的第一部分

这是我试过的,但不起作用

   string path =ConfigurationManager.AppSettings["LogDir"];
     string[] files = Directory.GetFiles("C:\Records", "Record_*" + ".txt", SearchOption.TopDirectoryOnly);

Example for my FileNames 
  Record_12345.txt
  Record_33124.txt
  Record_77624.txt

我想从C:\Records文件夹中读取所有文件名,如“Record_*.”.txt,我想您只需要在路径中添加第二个反斜杠(即确保正确转义斜杠)。其他一切看起来都很好

string path = ConfigurationManager.AppSettings["LogDir"];
string[] files = Directory.GetFiles("C:\\Records\\", "Record_*" + ".txt", SearchOption.TopDirectoryOnly);
你是说“.txt”还是“.text”,因为你同时提到了这两个词。