| How can I check if a file exists on the computer by a Visual Basic program?

How can I check if a file exists on the computer by a Visual Basic program?

SB asked:


I want to make a program that checks for a file if that file exists or not. I am adding certain actions that the computer will do if it finds that file but how can i make it check for its existance?

Related posts:

  1. Really Challenging Visual Basic Question Problem? ABC asked: I have a little problem. I need to...
  2. computer programming Visual Basic tutorial? John P asked: Can anyone show me how to work...
  3. How to write a program in Visual Basic to add, update, or delete records? Kevin asked: Okay, I’m about stressed to the limits right...
  4. Can i write BASIC or VISUAL BASIC programs on the internet? buckbucknumber2000 asked: I’d like to be able to write a...
  5. Visual Basic Programming Help? Bipul M asked: Does anyone know the code to save...

Filed Under Programming & Design |

Tagged With , ,

Comments

3 Responses to “How can I check if a file exists on the computer by a Visual Basic program?”

  1. Rawlyn on May 25th, 2009 5:54 am

    Here’s the p-code:

    1. Start in the root dir.
    2. List all files and dirs in the current dir.
    3. If file is present, stop. Otherwise, for each dir previously found, repeat steps 2 and 3.

    It’s easy enough to code once you know the logic, and now you know the logic!

    Rawlyn.

  2. Dr. Mr. Ed on May 27th, 2009 9:55 am

    In classic VB, you can use the Dir() function to do this. Supply the full path and filename as the argument like Dir(”c:\file.txt”) and if it’s there, this will be True; if it isn’t, False.

    In VB.NET, use the System.IO.File.Exists (”c:\file.txt”) static (er, Shared) method to do this.

  3. sparkylwg on May 27th, 2009 4:07 pm

    Hi There

    Create an instance of the filesystem object

    there is a method to check for existance which will return true or false

    objFSO.exists(Path)

    are you using vbscript or visual basic 6.0 or VB.NET?

    cheers

    Len