Many times it is Necessary to Know Programmatically
that the Specified File is Exist in Local Hard Drive, Although it Can be
Easily Achieved through FileSystemObject in VB, But it will Add a Large
Dependency to your Project.
Think of a Situation where you are not using
FileSystemObject Widely in your Project, then this dependency will
become major overhead to you.
I have Developed a Simple Function that will do this
job, without adding any dependency to your project, because it used
Simple VB functions.
|
Ö Source Code :
IsFileExist.Bas |
Public
Function IsFileExist(ByVal File As
String) As
Boolean
Dim Sret As
String
Dim FTitle As
String
FTitle = Mid(File, InStrRev(File, "\") + 1)
'Return Only File Name
Sret = Dir(File, vbNormal + vbReadOnly + vbHidden + vbArchive +
vbSystem)
If LCase(Sret) = LCase(FTitle)
Then
IsFileExist = True
Else
IsFileExist = False
End
If
End
Function |
The Function is Straight Forward. Argument should be in Full file
Path format e.g. "C:\Windows\App.txt" this function will first
Extract Actual filename e.g. App.txt, then using Dir function it
will check that the file is there or not, and Return the respective
Value to the caller.