Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force delete a folder being used by another process? [duplicate]

Tags:

c#

.net

directory

Possible Duplicate:
How can I delete a file that is in use by another process?

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:

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?

like image 233
DiverseAndRemote.com Avatar asked Oct 10 '12 16:10

DiverseAndRemote.com


People also ask

How do you force delete a folder that is being used?

Use “RMDIR /S /Q” command to force delete a folder in CMD: After entering Command Prompt window, you can type the rmdir /s /q folder path, for example, rmdir /s /q E:\test, and press Enter key. This deletes the folder named “test” in my USB drive.

How do you force delete a folder that won't delete?

Open elevated Command Prompt in Windows 10. Type del + file path command, press Enter to force delete file. Type rmdir /s /q + folder directory, press Enter to force delete folder Windows 10.


1 Answers

no, not without stopping the other process

like image 71
paul Avatar answered Oct 13 '22 00:10

paul