• 4 Red Pixels
    • Pete's Brain
    • Dare Night
  • Projects
    • Secret Santa Generator
    • Lottery Ticket Generator
    • Twister Auto-Spinner
    • Build your own javascript Countdown timer
    • Multiple Timers
    • Boggle Solver
  • Blog
  • Search
  • Get Social
    • Share My Circle
    • Google+
    • Twitter
4 red pixels 4 Red Pixels

You are here: Home » Blog » Visual Basic 6: Check directory or file exists

Visual Basic 6: Check directory or file exists

When opening files or directories from within a Visual Basic application you need to check that the file or directory exist, rather than crashing the appliaction and returning un-necessary errors.

The following 2 functions I use to see if the file and directories exist.

The functions will return the value "true" if the file or drectory do exist, and "false" if not.

Public Function FileExists(filename As String) As Boolean
    On Error GoTo ErrorHandler
    FileExists = (GetAttr(filename) And vbDirectory) = 0
ErrorHandler:
End Function

Function DirExists(DirName As String) As Boolean
    On Error GoTo ErrorHandler
    DirExists = GetAttr(DirName) And vbDirectory
ErrorHandler:
End Function

Author: 4 Red Pixels

Share this on...

Leave a comment...

Top content

  • Facebook Chat Emoticons
  • Facebook Status Games
  • Learn the Lingo
  • Turn your computer into a strobe light
  • PHP login example using MySQL and Session Cookies

© Copyright 4 Red Pixels - Be cool: share, don't steal!

Login to this website

Login with Google

Login with Facebook