Results 1 to 9 of 9

Thread: Does File Exist?

  1. #1

    Thread Starter
    Fanatic Member eimroda's Avatar
    Join Date
    Jul 2000
    Location
    Philippines
    Posts
    642

    Does File Exist?

    How can I determine if a file exists in a given directory?
    On Error GoTo Hell

    Hell:
    Kill Me


    Food For Thought:

    - Do not judge a book... if you're not a judge!


  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    use the DIR function.. explantion in VB help

  3. #3

    Thread Starter
    Fanatic Member eimroda's Avatar
    Join Date
    Jul 2000
    Location
    Philippines
    Posts
    642
    I dont have MSDN, can you pls show the code here?
    On Error GoTo Hell

    Hell:
    Kill Me


    Food For Thought:

    - Do not judge a book... if you're not a judge!


  4. #4
    Fanatic Member skald2k's Avatar
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    535
    VB Code:
    1. Dim fso as fileSystemObject
    2.  
    3. msgbox fso.fileExists("C:\whateverfile.whatever")

    You need a reference from your project to Microsoft Scripting Runtime library.
    Last edited by skald2k; Oct 15th, 2002 at 06:11 AM.
    - If at first you dont succeed, then give up, cause you will never will!

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Originally posted by eimroda
    I dont have MSDN, can you pls show the code here?
    You don't need MSDN, just standard VB help files..

    If Dir ("c:\windows\test.txt") <> "" Then
    'It Exists
    Else
    'It doesn't
    End If

  6. #6

    Thread Starter
    Fanatic Member eimroda's Avatar
    Join Date
    Jul 2000
    Location
    Philippines
    Posts
    642
    Thank you skald2k! I'll give your code a try...
    On Error GoTo Hell

    Hell:
    Kill Me


    Food For Thought:

    - Do not judge a book... if you're not a judge!


  7. #7
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    VB Code:
    1. If Dir$([i]path[/i]) <> "" Then
    2.  'The File Exists
    3. Else
    4.  'The File Does Not Exist
    5. End If
    Luke

  8. #8

    Thread Starter
    Fanatic Member eimroda's Avatar
    Join Date
    Jul 2000
    Location
    Philippines
    Posts
    642
    Thank you all guys! I got it!!!!
    On Error GoTo Hell

    Hell:
    Kill Me


    Food For Thought:

    - Do not judge a book... if you're not a judge!


  9. #9
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    No prob
    Luke

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