how to check if a directory exists or not?

Posted on 2004-08-04
Last Modified: 2010-04-23
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..
Question by:ajaypappan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 27

Expert Comment

ID: 11718321
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

Author Comment

ID: 11718344
I am using vb5...
LVL 27

Expert Comment

ID: 11718417
why are you posting in
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 11718436
can anyone move it to vb section..?
LVL 27

Accepted Solution

planocz earned 50 total points
ID: 11718509
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
LVL 27

Expert Comment

ID: 11718583
LVL 96

Expert Comment

by:Bob Learned
ID: 11722491
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.


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question