|
-
Oct 4th, 2000, 06:58 PM
#1
Thread Starter
New Member
Please tell me a good way to search a file in the hard drive given i know the file path. i want to search a file in a dirctory. for example, lets assume i have directory call "apps" and i want to search for file in this dirctory.
-
Oct 4th, 2000, 07:13 PM
#2
Use the Dir function.
Code:
If Dir("C:\apps\myfile.exe") <> "" Then
Msgbox "file exists"
Else
Msgbox "file not found"
End If
-
Oct 4th, 2000, 07:17 PM
#3
Lively Member
'Put in form
If FileExists("c:\myapps\myfile.exe") Then
'file exists
else
'file does NOT exists
End if
'Put in module
Public Function FileExists(strPath) As Boolean
Dim fnum
fnum = FreeFile
FileExists = True
On Error GoTo err
Open strPath For Input As fnum
Close fnum
Exit Function
err:
Close fnum
FileExists = False
End Function
-
Oct 4th, 2000, 07:38 PM
#4
Dir function is much simpler and faster as well (I believe) .
If you want it in a function:
Code:
Private Function FileExists(file As String) As Boolean
If Dir(file) <> "" Then
FileExists = True
Else
FileExists = False
End If
End Function
Usage:
If FileExists("C:\apps\myfile.exe") Then
Msgbox "file exists"
Else
Msgbox "file not found"
End If
-
Oct 4th, 2000, 07:44 PM
#5
Lively Member
Yes, I used to use the DIR, but becomes useless when you're checking the existence of a file whilst already in a loop using DIR.
Solved many debug problems by dropping the DIR in favour of other methods.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|