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?
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.
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.
no, not without stopping the other process
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With