0

如何从文件夹中读取所有相似的文件名。C:\Records 文件夹中的“Record_*”.txt 等文件名。例如,我的文件名以 Record_.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

4

1 回答 1

2

我认为您只需要在路径中添加第二个反斜杠(即确保正确转义斜杠)。其他一切看起来都不错

string path = ConfigurationManager.AppSettings["LogDir"];
string[] files = Directory.GetFiles("C:\\Records\\", "Record_*" + ".txt", SearchOption.TopDirectoryOnly);
于 2012-11-02T22:23:10.703 回答