Directory in Use  
Author Message
j_o_h_a_n_n_e_s





PostPosted: Visual Basic Express Edition, Directory in Use Top

Hi everyone!

I am currently writing an app that needs to delete a directory, however, when I use the Filesystem.DeleteDirectory, I get an error "Directory in use." I've checked all the connections in my app, but can't find any answers.

Can anyone please help me

Johannes



Visual Studio Express Editions40  
 
 
Tall Dude





PostPosted: Visual Basic Express Edition, Directory in Use Top

Is the directory in question a system created folder

Some program, most likely the operating system has a file

open in the folder or one of it's subfolders.



 
 
DMan1





PostPosted: Visual Basic Express Edition, Directory in Use Top

Also...if the directory is being viewed in explorer you will get that error

...you may also want to explicitly use the "DeleteAllContents" constant with the method:

Public Const DeleteAllContents As Microsoft.VisualBasic.FileIO.DeleteDirectoryOption = 5

Member of: Microsoft.VisualBasic.FileIO.DeleteDirectoryOption

Summary:

Delete the contents of the directory along with the directory. Default.



 
 
j_o_h_a_n_n_e_s





PostPosted: Visual Basic Express Edition, Directory in Use Top

No, the directory is not a system directory.

I tried running it with Explorer closed, but still got the same error.

Thanks anyway :-)


 
 
j_o_h_a_n_n_e_s





PostPosted: Visual Basic Express Edition, Directory in Use Top

Hi!

Is there a specific "all-in-one" method that I can deploy to delete the directory and its contents

Thanks


 
 
Tall Dude





PostPosted: Visual Basic Express Edition, Directory in Use Top

No, there is no all-in-one.

You must be able to understand and handle errors and

limitations that the operating system may throw at you.

For example:

My.Computer.FileSystem.CurrentDirectory = ("c:\aaa")

My.Computer.FileSystem.DeleteDirectory("C:\aaa", FileIO.UIOption.AllDialogs, FileIO.RecycleOption.SendToRecycleBin)

Will cause your error, because your program has the directory to be deleted as it's

current directory.

If the first line is omitted, line 2 works with no error.



 
 
j_o_h_a_n_n_e_s





PostPosted: Visual Basic Express Edition, Directory in Use Top

Thanks very much!!! Didn't spot that...

Johannes