VB and VBA Users Source Code: Search a folder (and all it's subfolders) for a file
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Search a folder (and all it's subfolders) for a file
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, March 14, 2001
Hits:
998
Category:
Windows API
Article:
Option Explicit Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal RootPath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long 'Purpose : Searches a folder (and all it's subfolders) to locate a file. 'Inputs : sFileName The file to search for ' sRootPath The path to start the search in. 'Outputs : Returns the path and name of the file on success, else ' returns an empty string. 'Author : Andrew Baker 'Date : 03/09/2000 13:58 'Notes : Doesn't support wildcards. 'Revisions : Function FileFind(sFileName As String, sRootPath As String) As String Const MAX_PATH = 260 Dim sResult As String * MAX_PATH, lRetValue As Long lRetValue = SearchTreeForFile(sRootPath, sFileName, sResult) If lRetValue <> 0 Then 'File found FileFind = Left$(sResult, InStr(1, sResult, Chr$(0)) - 1) Else 'File not found FileFind = "" End If End Function 'Demonstration routine Sub Test() Debug.Print FileFind("comctl32.ocx", "c:\") End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder