Solved

how to check if a directory exists or not?

Posted on 2004-08-04
7
1,137 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now