Its been ages, so simple ive forgotten

Hey experts - not exactly a hard one but its been so long i cant remember how to do this.

If a directory, for example C:\Program Files\Directory, does not exist then make it, and if it does exist then delete it and make it again.

So -    Dir exist?         Yes - Delete and remake
                                No - Make

I know its something to do with mkdir, rmdir but i cant remember how to see if it exists or not.  ive been playing around with

If ("C:\Program Files\Directory") = "" Then    ..... but to no avail.

Thanks Experts, not very challanging i know but its still points :-)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shiju SasidharanAssoc Project ManagerCommented:
try this
'Dont forget to add referece
'Project Menu->References
'   Microsoft Scripting Runtime
Private Sub MakeDirectory(sFolderName As String, Optional ByVal Overwrite As Boolean)
Dim objFso As New FileSystemObject
On Error GoTo Er:
    If Trim(sFolderName) = "" Then
        MsgBox "Invalid Folder Name"
        Exit Sub
    End If
    If objFso.FolderExists(sFolderName) Then
        If Overwrite Then
            objFso.DeleteFolder (sFolderName)
            objFso.CreateFolder (sFolderName)
        End If
        objFso.CreateFolder (sFolderName)
    End If
    Exit Sub
    MsgBox "Unable to Create/Delete Folder : " & Err.Description

End Sub
'Private Sub Command1_Click()
'    Call MakeDirectory("d:\test", True)
'End Sub
cofneverlivetotellAuthor Commented:
:-|   isnt that a *little* overcomplicated?  lol i just need to see if a dir exists or not and make a decision, a few lines like i have will do it but i cant remember how.  like you can see if a string is empty and act upon  it with

If strTeststring = "" then
End if

Get my thinking?  Ive got a perfect app apart from this one little thing (this is an updater for sophos antivirus, ive made a program to download and unzip the virus identities to the ide folder, but i need to delete another folder if it exists and remake it, or just make if it doesnt exist)


Are you thinking of something like

 Dim dPath As String
 dPath = "C:\Program Files\Directory"
 On Error Resume Next
 MkDir dPath
 If Err.Number <> 0 Then
  Kill dPath & "\*.*"
  RmDir dPath
  MkDir dPath
 End If
 On Error GoTo 0


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

cofneverlivetotellAuthor Commented:
Yup, that does it great.  Thanks mvidas
I think you were looking for something like this:

If Dir("C:\Program Files\Directory", vbDirectory) <> "" Then
    MsgBox "Directory exists"
    MsgBox "Directory Does Not Exist"
End If
cofneverlivetotellAuthor Commented:
Yeah, that was basicly what i was looking for, but mvidas gave another working and reasonably simple answer... If it wasnt accepted i would give you the points for simplicity, but no can do :-(

I realized the answer was already accepted but it's not all about the points.I thought the info might help you as in my opinion it is a better solution then error trapping and from your comments it sounded as if it was what you were looking for.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.