我正在尝试使用 c# DirectoryInfo.getFiles 从目录中读取文件,但它返回一个空数组。即使文件夹中有一个文件,它也具有所有访问权限,并且没有抛出异常。虽然,当我尝试在“即时窗口”(VS 2010)中运行该行时,它会正确地从目录中获取文件。
我在谷歌上搜索,但到目前为止我没有找到答案。有什么我错过的吗?
代码非常简单:
try
{
DirectoryInfo pathDir = new DirectoryInfo(this.path);
FileInfo[] files = pathDir.GetFiles();
foreach (FileInfo file in files)
{
XmlDocument xml = new XmlDocument();
xml.Load(file.fullName);
// doing something with XML here
}
}
catch (Exception exc)
{
Console.WriteLine("The following error has occured: " + exc.Message.ToString());
}