Link to home
Start Free TrialLog in
Avatar of ajaypappan
ajaypappanFlag for United States of America

asked on

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 & "\*.*")
Else
MkDir (ad)
End If

My file path is K:\Apps\CBS\MCI\0728 and it has to check for another 0728 directory in that..
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

hi,
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
               fiTemp.delete  
            End If
        Next fiTemp
    End Sub
Avatar of ajaypappan

ASKER

I am using vb5...
why are you posting in vb.net?
can anyone move it to vb section..?
ASKER CERTIFIED SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

Bob