how to check if a directory exists or not?

I am trying to check if a directory exist or not , if yes  delete the contents and new contents

On Error Resume Next
ad = File1.Path & "\" & ab
Fpath = File1.Path
If (GetAttr(ab) And vbDirectory) Then
Kill (File1.Path & "\" & ab & "\*.*")
MkDir (ad)
End If

My file path is K:\Apps\CBS\MCI\0728 and it has to check for another 0728 directory in that..
Who is Participating?

Improve company productivity with a Business Account.Sign Up

planoczConnect With a Mentor Commented:
check links....


Dim FSO As FileSystemObject
Set FSO = New FileSystemObject

If FSO.FolderExists("C:\winnt") Then
    Debug.Print "Exists"
    Debug.Print "Doesn't"
End If

Set FSO = Nothing
here is some code. I may have missed a piece.
just run it with break points and look to see if this will work for you.

dim MYPath  as string =" K:\Apps\CBS\MCI\0728"

Imports System.IO

   Public Sub GetALLFiles(byval MYPath as string)
        ' Create a reference to the current directory.
        Dim di As New DirectoryInfo(MYPath)
        ' Create an array representing the files in the current directory.
        Dim fi As FileInfo() = di.GetFiles()
        Dim fiTemp As FileInfo
         For Each fiTemp In fi
            If fiTemp.Exists = true Then
            End If
        Next fiTemp
    End Sub
ajaypappanAuthor Commented:
I am using vb5...
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

why are you posting in
ajaypappanAuthor Commented:
can anyone move it to vb section..?
Bob LearnedCommented:
Also, If Len(Dir$(path, vbDirectory)) > 0.  

planocz has the right approach.

To move a question to another topic area, post a free question in the Community Support topic area, and ask a moderator to move the question, giving them the URL.

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.

All Courses

From novice to tech pro — start learning today.