PDA

Click to See Complete Forum and Search --> : How to scan for a file.


MiDaWe
Nov 26th, 1999, 08:05 AM
Can anyone help me with this?

I want my program to scan and find the computer drives for a certain file.

If the file is on the computer then I need to load the location into a string.

Can anyone help me?

------------------
Thanks,
MiDaWe

Aaron Young
Nov 26th, 1999, 12:51 PM
Try Something Like this:

Private Sub Command1_Click()
MsgBox FindFile(Text1, "C:\")
End Sub

Function FindFile(ByVal sFileName As String, Optional ByVal sInitPath As String) As String
If IsMissing(sInitPath) Then sInitPath = CurDir
Dim aSubDirs() As String
Dim iDirs As Long
Dim sDir As String

If Right$(sInitPath, 1) <> "\" Then sInitPath = sInitPath & "\"
sDir = Dir(sInitPath & "*", vbDirectory + vbNormal + vbHidden + vbReadOnly + vbSystem)
While Len(sDir)
If LCase(sDir) = LCase(sFileName) Then
FindFile = sInitPath & sDir
Exit Function
Else
If (GetAttr(sInitPath & sDir) And vbDirectory) = vbDirectory And Left$(sDir, 1) <> "." Then
ReDim Preserve aSubDirs(iDirs)
aSubDirs(iDirs) = sDir
iDirs = iDirs + 1
End If
End If
sDir = Dir
Wend

If iDirs Then
For iDirs = 0 To UBound(aSubDirs)
FindFile = FindFile(sFileName, sInitPath & aSubDirs(iDirs))
If Len(FindFile) Then Exit For
Next
End If
End Function


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net