MsgBox "NWIND.MDB was not found on drive C"
End if
Should you have knowledge of the folder where NWIND.MDB is supposed to be located, you could use sysFileFind to scan that folder and any of its subfolders. For example:
MsgBox "NWIND.MDB was not found in C:\Program Files or any of its subfolders."
End if
Declare
Public Declare Function SearchTreeForFile Lib "imagehlp.dll" (ByVal lpRoothPath As String, ByVal lpInputName As String, ByVal lpOutputName As String) As Long
Public Function sysFileFind(ByVal WhichRootPath As String, ByVal WhichFileName As String) As String
'Remember To add Reference to Microsoft Scripting Runtime
'in references
'Author:Sachin
Option Explicit
Dim fso As FileSystemObject
Private Sub Command1_Click()
Set fso = New FileSystemObject
fspenTextFile "c:\1.htm", ForReading
If fso.FileExists("c:\1.htm" Then
MsgBox "exists"
Else
MsgBox "Doesn't exists"
End If
Yes, it can be done by including FileExists in a recursive function. Here's a (rather ropey) example: [tt]
Option Explicit
Public Function SeekFile(strFile As String, strStartPath As String) As String
' Remember To add Reference to Microsoft Scripting Runtime
Dim fso As FileSystemObject
Dim StartFolder As Folder
Dim SearchFolder As Folder
Dim FolderName As String
SeekFile = ""
Set fso = New FileSystemObject
Set StartFolder = fso.GetFolder(strStartPath)
FolderName = StartFolder
' Add trailing backslash if not root folder
If Not StartFolder.IsRootFolder Then FolderName = FolderName + "\"
' Look for file in currently selected folder
If fso.FileExists(FolderName & strFile) Then
SeekFile = StartFolder 'Aha, we've found it
Else
' We didn't find it, so look in all subfolders of
' the current folder
For Each SearchFolder In StartFolder.SubFolders
SeekFile = SeekFile(strFile, SearchFolder.Path)
If SeekFile <> "" Then
Exit For
End If
Next
End If
End Function
Sub main()
Dim oDrive As Drive
Dim oFolder As Folder
Dim oFSO As FileSystemObject
Set oFSO = New FileSystemObject
Set oDrive = oFSO.GetDrive("C:"
Set oFSO = Nothing
Set oFolder = oDrive.RootFolder
Set oDrive = Nothing
MsgBox FindFile(oFolder, "Copy of mypage.html"
Set oFolder = Nothing
End Sub
Private Function FindFile(ByVal oFolder As Folder, ByVal sFile As String) As String
Dim oFile As File
Dim oSubFolder As Folder
For Each oFile In oFolder.Files
If LCase$(oFile.Name) = LCase$(sFile) Then
FindFile = oFile.Path
Set oFile = Nothing
Set oFolder = Nothing
Exit Function
End If
Next oFile
Set oFile = Nothing
For Each oSubFolder In oFolder.SubFolders
FindFile = FindFile(oSubFolder, sFile)
If FindFile <> "" Then
Set oSubFolder = Nothing
Set oFolder = Nothing
Exit Function
End If
Next oSubFolder
Set oSubFolder = Nothing
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.