Results 1 to 3 of 3

Thread: How do I find if a file or directory exists?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    1

    Question

    I've ready many articles and tutorials, all the same, about how to open and close files. And how to use file boxes to browse for files.

    What I wan't to do is be able to check if a directory or file already exists, but without user intervention. An example would be a batch file command like "IF EXIST blah.txt THEN dowhatever"

    Is there something like I could use if VB?

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    You can use the Dir Function to check if a file exist.

    Code:
    Private Sub Command1_Click()
    If Dir("C:\test.txt") = "" Then
        MsgBox "File dont exist"
    Else
        MsgBox "File Exist"
    End If
    End Sub
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3
    Guest
    To check if a directory exists, also using the Dir function:

    Code:
    Private Sub Command1_Click()
    If Dir("C:\MyFolder", vbDirectory) <> "" Then
        MsgBox "Folder exists"
    Else
        MsgBox "Folder does not exist"
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width