Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB.NET

i want to delete a folder using below code. Normally it works but when the testfolder is open, below code got an exception.

My.Computer.FileSystem.DeleteDirectory("testfolder", FileIO.DeleteDirectoryOption.DeleteAllContents)


is there any way to delete the folder even when the folder is open.

What I have tried:

tried several delete method, no one worked.
Posted
Updated 9-Oct-17 6:48am

No, if the folder is open, that means that an application is using a file in it - and you can't delete the folder without messing up that app.

Use a try...catch block to catch the exception, tell the user, and give him a chance to re-try when he has closed the file.
 
Share this answer
 
Quote:
is there any way to delete the folder even when the folder is open.

No, it is the OS job to prevent it to happen.
The only way to do it is the have all other apps to close the files they opened in that folder.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900