VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

FindFile Fast, using the API

Dave Hng  (4 Submissions)   Files/File Controls/Input/Output   Visual Basic 3.0   Unknown Difficulty   Wed 3rd February 2021

Uses the FindFile, FindNextFile, and SearchPath API functions to quickly find a file on your hard drive. Runs faster than methods which use Dir$.

Inputs
Filename - Filename to search for. Path - The path to start searching from.

Assumes
None, if you want to find out what the API does exactly, read the Win32SDK. It's great for stuff like that!

Returns
Returns the full path to the filename, if it found it. Otherwise, returns an empty string ("").

Side Effects
Since the function's recursive, i guess you could hit a stack overflow if you had an obscene number of folders to search through :)

API Declarations
'Lots here.. :)
Public Const MAX_PATH As Long = 260
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
Type FileTime
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FileTime
ftLastAccessTime As FileTime
ftLastWriteTime As FileTime
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Public Declare Function SearchPath Lib "kernel32" Alias "SearchPathA" (ByVal lpPath As String, ByVal lpFileName As String, ByVal lpExtension As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long

Rate FindFile Fast, using the API (21(21 Vote))
FindFile Fast, using the API.bas

FindFile Fast, using the API Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters