Solved

how to check if a directory exists or not?

Posted on 2004-08-04
7
1,136 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

8 Experts available now in Live!

Get 1:1 Help Now