Solved

how to check if a directory exists or not?

Posted on 2004-08-04
7
1,139 Views
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 & "\*.*")
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..
0
Comment
Question by:ajaypappan
  • 4
  • 2
7 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 11718321
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
0
 
LVL 3

Author Comment

by:ajaypappan
ID: 11718344
I am using vb5...
0
 
LVL 27

Expert Comment

by:planocz
ID: 11718417
why are you posting in vb.net?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
LVL 3

Author Comment

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

Accepted Solution

by:
planocz earned 50 total points
ID: 11718509
check links....

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20595372.html

http://www.freevbcode.com/ShowCode.Asp?ID=1981


sample:

Dim FSO As FileSystemObject
Set FSO = New FileSystemObject

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

Set FSO = Nothing
0
 
LVL 27

Expert Comment

by:planocz
ID: 11718583
0
 
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.

Bob
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…

821 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