Delete(strDirPath, true) gives "the directory is not empty"

  • Thread starter Thread starter codeboy
  • Start date Start date
C

codeboy

I am using VS2008 to create a website. When I try to programmatically delete
a directory that is located within my website I will get an error. I am
trying to delete the directory using “System.IO.Directory.Delete(strDirPath,
true)â€. This is the message the error gives "the directory is not empty". I
found another entry titled “Directory.Delete of a non empty dir fails in
ASP.NET applicationâ€. In that posting Walter Wang says: “the folder is
locked by Visual Studio 2005 IDE if the folder is already shown in project
explorerâ€. Now that I am using VS2008 has this been changed? How can I test
my code? Please help me get past this problem.

Thanks
 
re:
!> How can I test my code?

Create an IIS virtual directory and test directory.delete with VS 2008 closed.

You can undo the IIS virtual directory when you've finished testing directory.delete.

When done testing directory.delete, open VS 2008 and continue testing the rest of the code.




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
 
This seems like a very cumbersome way of tying to handle the problem. I also
like to use the debugging tools. They will not be available if VS2008 is
closed. I need a way of testing my code within the development environment
without getting this error. How can I do this?
 
re:
!> This seems like a very cumbersome way of tying to handle the problem.

Given that VS 2008 locks the directory, it's the only way to do it.

re:
!> I also like to use the debugging tools. They will not be available if VS2008 is closed.

Of course not, but testing directory.delete doesn't really require a lot of debugging, does it ?
Do a simple test...and learn the correct way to handle directory deletions in IIS.

re:
!> I need a way of testing my code within the development
!> environment without getting this error. How can I do this?

File a bug report and wait for it to be fixed.

Also, you might want to check to see whether any files are in the directory.
You'll have to delete the files first before deleting the directory.

Also, are you sure the directory is not set as a read-only directory ?

See code to do that at :
http://www.eggheadcafe.com/conversation.aspx?messageid=33335128&threadid=33307218




Juan T. Llibre, asp.net MVP
¿ Estas probando VS 2010 y ASP.NET 4.0 ?
Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
http://asp.net.do/foros/forums/
=====================================================
 
Back
Top