Solved

how to check if a directory exists or not?

Posted on 2004-08-04
7
1,138 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 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