PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
Check File Exists
This function determines whether a specified file exists in a given directory. The function returns True or False, when passed the full filepath (including the filename and extension). The function separates the directory and filename, then searches that directory for the given filename. This function also makes use of the GetFileName function to return the filename from it's path. Add the following code to a FileHandling.bas standard module to compile a File Utility function set:
Function CheckFileThere(FullPath As String) As Boolean

'*******************************************************
'<DESC>		Checks if a file exists in a given 
'		directory</DESC>
'<RETURN>	Boolean:
'			<LI> TRUE, File Exists
'			<LI> FALSE, File not Found</RETURN>
'<ACCESS>	Public
'<ARGS>		FullPath: 
'			Full Filepath incl. Filename
'				</ARGS>
'<USAGE>	If CheckFileThere("c:\autoexec.bat") then...
'				</USAGE>
'*******************************************************

    Dim intCheckThere As Integer
    Dim strSearchFile As String
    Dim strFileName As String

    strFilename = Trim$(UCase$(GetFileName(FullPath)))
    strSearchFile = Trim$(UCase$(FullPath))
    On Error Resume Next
    If UCase$(Trim$(Dir(strSearchFile, 0))) = strFilename Then
        If Err.Number = 76 Then
            intCheckThere = False
        Else
            intCheckThere = True
        End If
    Else
        intCheckThere = False
    End If
    CheckFileThere = intCheckThere

End Function
 

Top of Page

Legal Notice

Ken Howe 2011