删除的文件仍然出现在Directory.GetFiles结果 [英] Deleted file still appears in Directory.GetFiles result

查看:111
本文介绍了删除的文件仍然出现在Directory.GetFiles结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个webMethods的。第一个是:

I have two webmethods. The first is:

void deleteFile(string filePath)
{
  File.Delete(filePath);
}



另一种是:

The other is:

string[] getAllFile()
{
  // at the same folder....
  Directory.GetFiles("*.xml");
  .....
  return ....   
}

我调用这些方法如下所示:

I'm calling these methods like so:

deleteFile("1.xml")
getAllFile();



尽管删除1.XML文件,调用目录。的GetFiles(*。xml的); 仍处于并将结果返回1.XML。换句话说,它似乎并没有被删除。

Despite deleting the "1.xml" file, the call to Directory.GetFiles("*.xml"); still returns "1.xml" in the results. In other words, it doesn't seem to have been deleted.

然后,当我循环的结果,尝试读取这个文件,得到FileNoFoundException

And then, when I loop the result , try to read the file , get the FileNoFoundException

推荐答案

我发现的DirectoryInfo / FileInfo的课并不总是更新。在这些情况下,您需要调用的目录/文件实例刷新方法。

I've found that the DirectoryInfo/FileInfo classes do not always update. In those instances you need to call the Refresh method on the Directory/File instances.

这篇关于删除的文件仍然出现在Directory.GetFiles结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆