如何强制删除文件夹被另一个进程?夹被、进程、文件

2023-09-03 03:50:09 作者:一路&狂奔

可能重复:   How我可以删除一个文件,该文件是由另一个进程使用?

我有以下的C#code,但它抛出在调用Delete方法异常:

I have the following c# code but it throws an exception on the call to the Delete method:

var dir = new DirectoryInfo(@"C:\mydirectory\");
dir.Delete(true);

下面抛出异常:

The following exception is thrown:

该进程无法访问该文件'C:\ mydirectory,因为它正由另一个进程使用

The process cannot access the file 'C:\mydirectory' because it is being used by another process.

有没有什么办法,迫使它删除这个目录,即使它正在被其它进程?

Is there any way to force it to delete this directory even though it's being used by another process?

推荐答案

没有,不是没有停止其他进程

no, not without stopping the other process