How do I create a directory?

ZorroRojo

Member
Joined
Oct 9, 2006
Messages
15
Location
Virginia, US
Programming Experience
Beginner
I've managed to learn how to delete a directory.

VB.NET:
Dim objDirectory AsNew DirectoryInfo("c:\data\WrongDate")
 
'If the directory WrongDate exists it gets deleted and recreated.
'This ensures files from the previous day are not in the directory.
If objDirectory.Exists Then
objDirectory.Delete()
EndIf
So how do I create it again?

I want to delete and recreate the same directory to get rid of all the files in the directory.
 
Last edited by a moderator:

Raven65

Well-known member
Joined
Oct 4, 2006
Messages
305
Programming Experience
3-5
Seems like a more sound approach to just delete all files in the directory each day...is there a reason not to?

VB.NET:
Imports System.IO
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim dir As String = "C:\Test\"
        Dim file As String
        Dim files As String() = Directory.GetFiles(dir)

        For Each file In files
            System.IO.File.Delete(file)
        Next
    End Sub
End Class
 

ZorroRojo

Member
Joined
Oct 9, 2006
Messages
15
Location
Virginia, US
Programming Experience
Beginner
Well, I figure it would be quicker to delete the folder and recreate it rather than delete 17 or so files.

And as soon as I saw your reply I realized I forgot to put my code in a code box.

I guess it won't take too much extra time to delete each file individually.
 
Top Bottom