Advertisement
Java_Volume1 Files/ File Controls/ Input/ Output #90214

A Find File Procedure No Looping

This procedure finds a file and returns the full path, provided a partial path it will search all sub dirs. No looping only 1 API - this is the kind. I can't really take credit for putting an api to use, just sharing something that you might find useful.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Private Function FindFile(sFile As String, sRootPath As String) As String
 ' Search for the file specified and return the full path if found
 Dim sPathBuffer As String
 Dim iEnd As Integer
 
 'Allocate some buffer space (you may need more)
 sPathBuffer = Space(512)
 
 If SearchTreeForFile(sRootPath, sFile, sPathBuffer) Then
  'Strip off the null string that will be returned following the path name
  iEnd = InStr(1, sPathBuffer, vbNullChar, vbTextCompare)
  sPathBuffer = Left$(sPathBuffer, iEnd - 1)
  FindFile = sPathBuffer
 Else
  FindFile = vbNullString
 End If
End Function
Original Comments (3)
Recovered from Wayback Machine