• 0

file exists check


Question

wow! i actually remembered to put the language in. i amaze even myself... :D

i am trying to see if a file "status.txt" exists, but all the code i have found on various coding sites wont work for some reason, or only works on .net VB etc :wacko:.

does anyone here know some simple VB6 compatible code to see if this file exists?

thanks in advance!

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

I'm not sure about VB 6, but a way to do it in almost every language is to try to open it, and see if an error occurs. If you get an error, you at least know that the file isn't available, and you can handle it the same way you wanted to if it didn't exist.

You could look at http://www.msdn.com (the microsoft developer network, with a lot of info about all MS development languages), but you'll probably get a lot of .net items.

Link to comment
Share on other sites

  • 0

' Return True if a file exists

Function FileExists(FileName As String) As Boolean
    On Error GoTo ErrorHandler
    ' get the attributes and ensure that it isn't a directory
    FileExists = (GetAttr(FileName) And vbDirectory) = 0
ErrorHandler:
    ' if an error occurs, this function returns False
End Function

http://www.devx.com/vb2themax/Tip/18942

Link to comment
Share on other sites

  • 0

It's a function. You put that in your code, and this to use it (it's pretty simple to understand, so you must be a newbie at VB):

If FileExists("C:\autoexec.bat") then

msgbox "it exists!"

else

msgbox "it doesn't!"

end if

Link to comment
Share on other sites

  • 0

oh right thanks. i guess you could call me a bit of a newbie @ vb. i know what i need to know, and no more :D

i guess i didn't know what i needed to know this time!

thanks again!

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.