none
vb.net 2003 Delete a Directory RRS feed

  • Question

  • Is there a way in vb 2003 to delete a directory and everything in it without having to detect and delete all the files first?

    directory.delete("c:/dummy") does not work.

     

    If the answer is no, do you have a code snippet for accomplishing such a deletion.

    Thanks,

    Fred

    Thursday, May 11, 2006 12:49 AM

Answers

  • a tip:

    when you type in directory.delete(
    and the intellisense pops up, it has

    v1 of 2^ Delete (path as string)

    If you press the down arrow key, then you see 2 of 2, which is the overload of delete that you can use to recurse and delete everything
    So:

            Try
                IO.Directory.Delete("C:\test", True)
            Catch ex As Exception
                ' better catch exceptions, file could be locked, readonly, blah...
            End Try
    Thursday, May 11, 2006 1:53 AM