VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Find Files using FindFirstFile,FindNextFile and FindClose API

by Karthikeyan (187 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Wed 1st August 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Find Files using FindFirstFile,FindNextFile and FindClose API

API Declarations


dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private 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 * 260
cAlternate As String * 14
End Type
Private Declare Function FindNextFile Lib "kernel32.dll" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindFirstFile Lib "kernel32.dll" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32.dll" (ByVal hFindFile As Long) As Long

Rate Find Files using FindFirstFile,FindNextFile and FindClose API



Dim handle As Long
Dim finfo As WIN32_FIND_DATA
Dim found As Long
Dim buffer As String
Dim rval As Long
Dim c As Integer
List1.Clear
handle = FindFirstFile(Text1.Text, finfo)'Find files in path entered in the textbox
If handle = -1 Then
MsgBox "No files found"
End
End If
c = 0
Do
buffer = Space(128)
buffer = Left(finfo.cFileName, InStr(finfo.cFileName, Chr(0)) - 1) 'Extract the found filename
buffer = buffer & "---------> " & finfo.nFileSizeLow & " Bytes"
'MsgBox buffer
List1.AddItem buffer, c
c = c + 1
found = FindNextFile(handle, finfo)
Loop Until found = 0
rval = FindClose(handle)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{TAB}"
SendKeys "{ENTER}"
End If
End Sub


Download this snippet    Add to My Saved Code

Find Files using FindFirstFile,FindNextFile and FindClose API Comments

No comments have been posted about Find Files using FindFirstFile,FindNextFile and FindClose API. Why not be the first to post a comment about Find Files using FindFirstFile,FindNextFile and FindClose API.

Post your comment

Subject:
Message:
0/1000 characters