Friday, July 31, 2009

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

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?

How can I check if a file exists on the computer by a Visual Basic program?
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.
Reply:imports system.io





.


.


.


.


.


.


if file.exists(file name) then


'code


end if





'or oyu can


try


fileopen() Report It

Reply: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
Reply: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.

night garden

No comments:

Post a Comment