many thank's
[ ]' Always
Here's a previous post of mine. It gives you an example of
FindFirstFile.
Follow these 3 steps to scan through files in a ...
1). Drop this code in a class module named FileLister:
'constants
Private Const MAX_PATH = 260
'declares
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As
Long)
As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias
"FindFirstFileA"
_
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As
Long
Private Declare Function FindNextFile Lib "kernel32" Alias
"FindNextFileA" _
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As
Long
'type declarations
Private Type FILETIME
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 * MAX_PATH
cAlternate As String * 14
End Type
Public Sub GetFiles(sFolder As String, ByRef sFileArray() As String)
Dim lret As Long
Dim lNext As Long
Dim lhClose As Long
Dim sFileSize As String
Dim FileRec As WIN32_FIND_DATA
'init array
ReDim sFileArray(0)
lret = FindFirstFile(sFolder, FileRec)
'if nothing returned
If lret = -1 Then
lhClose = FindClose(lret)
Exit Sub
End If
With FileRec
sFileArray(0) = Left(.cFileName, Len(.cFileName) - 1)
End With
lNext = -1
Do
lNext = FindNextFile(lret, FileRec)
If lNext <> 0 Then
With FileRec
ReDim Preserve sFileArray(UBound(sFileArray) + 1)
sFileArray(UBound(sFileArray)) = Left(.cFileName,
Len(.cFileName) - 1)
End With
End If
Loop Until lNext = 0
lhClose = FindClose(lret)
End Sub
2). Now you call Getfiles like this (NOTICE YOU CAN USE WILDCARDS!):
<somewhere on a form or whereever you want it>
dim fl as FileLister
set fl = new FileLister
fl.GetFiles "c:\windows\*.*", sArray
fl.GetFiles "c:\windows\*.wav", sArray
3). Just loop through sArray to see your files
;-) Cool
Hasta Luego
Adrian Maull [MCSD]
Some sample code at http://home.earthlink.net/~butlerbob/vb/disk/dirsize.htm
I have the source code for a small class (and demo application) which I have
tried to optimise for this purpose in view of "the need for speed". It uses
recursive techniques.
If you would like the source (approx 11k zipped), please e-mail me direct
and specify "FSearch" for Vb5 (using WinAPI FindFirst/FindNext) or Vb6
(using FileSystemObjects). No strings attached.
Barry Evans
Canberra, Australia
----------------------------
Pedro Faustino wrote in message <772r5n$pvk$1...@sagan.global-one.pt>...
Hi, i would like to use the FindFirstFile API Function to find a specific
file but i lack of examples ( Im a newbie on using API).If you know
anything about this function help me please....
many thank's
[ ]' Always