How to Find a file in a specific location
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 'File/Folder Handling - How to Find a file in a specific location Option Explicit Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal RootPath As String, _ ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long Private Const MAX_PATH = 260 Private Sub Command1_Click() Dim strTemp As String strTemp = FindFile("D:\", "TempCP.txt") If strTemp = "" Then MsgBox "File not found" Else MsgBox strTemp End If End Sub Private Function FindFile(ByVal Path As String, ByVal FileName As String) As String Dim tempStr As String, Ret As Long Screen.MousePointer = vbHourglass 'create a buffer string tempStr = String(MAX_PATH, 0) 'returns 1 when successfull, 0 when failed Ret = SearchTreeForFile(Path, FileName, tempStr) If Ret <> 0 Then FindFile = Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1) Else FindFile = "" End If Screen.MousePointer = vbNormal End Function |