我必须检查不同目录数组中的每个 xml 文件。
我的代码(仍然有错误):
string files = "C:\Hello; C:\Hi; D:\Goodmorning; D:\Goodafternoon; E:\Goodevening";
//Get each path and remove whitespaces
string[] paths = files.Split(new[] { ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
//Use xmlLoc for adding \ to each file
List<string> xmlLoc = new List<string>();
//get the files in directories
string[] getFiles;
//contains the files of each directory
List<string> xmlList
//Add \ each paths variable and store it in xmlLoc list
foreach (string s in paths)
{
xmlLoc.Add(s + @"\");
}
//get the xml files of each directory in xmlLoc and store it in xmlList
foreach (string file in xmlLoc)
{
getFiles = Directory.GetFiles(file, "*.xml");
//the code below lists an error "cannot convert from string[] to string"
xmlList.Add(getFiles);
}
我猜您不能将数组存储在字符串列表中。是否有任何其他方式可以读取存储在数组中的每个目录中的文件?