如何删除一个文件,该文件是由另一个进程使用? [英] How can I delete a file that is in use by another process?
本文介绍了如何删除一个文件,该文件是由另一个进程使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试删除文件时发生以下异常:
When I try to delete a file occurs the following exception:
该进程无法访问该文件'' 因为它是正由另一个 流程。
The process cannot access the file '' because it is being used by another process.
我的code是这样的:
My code looks like:
string[] files = Directory.GetFiles(@"C:\SEDocumentConverter\SOURCE");
foreach (string file in files)
{
File.Delete(file);
}
我该如何解决这个问题呢?
How can I solve this problem?
推荐答案
有没有办法删除多数民众赞成目前正由另一个进程使用的文件。你必须关闭任何程序具有该文件第一次打开,然后才能将其删除。
There is no way to delete a file that's currently being used by another process. You have to close whatever program has that file open first, before you can delete it.
如果您还不知道哪个程序是,你可以使用的手柄或的Process Explorer 。
If you don't already know which program that is, you can figure it out using Handle or Process Explorer.
这篇关于如何删除一个文件,该文件是由另一个进程使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文