Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Functions to find if file exists...

Total Hit ( 1601)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
Public Function FileExists(filename As String) As Boolean
  FileExists = (Dir(filename, vbNormal Or vbReadOnly Or vbHidden Or vbSystem Or vbArchive) <> "")
End Function

Usage

Click here to copy the following block
'Usage:
Private Sub Command1_Click()
  If FileExists("C:\Config.sys") Then
    MsgBox "Config.sys is available"
  Else
    MsgBox "Sorry Can't find Config.sys"
  End If
End Sub


Click here to copy the following block
'Using the DIR function may not be the best way to determine
'if a file exists, especially if you are using VB to compare two
'directories, and take actions when the files do not match.
Function FileExist(sTestFile As String) As Boolean
  'This function does not use DIR since it is possible that you might have
  'been in the middle of running DIR against another directory in
  'an attempt to match one directory against another.

  'It does not handle wildcard characters
  Dim lSize As Long
  On Error Resume Next
  'Preset length to -1 because files can be zero bytes in length
  lSize = -1
  'Get the length of the file
  lSize = FileLen(sTestFile)
  If lSize > -1 Then
    FileExist = True
  Else
    FileExist = False
  End If
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.