Hi All,
I'm working on a program that requires searching multiple drives for multiple file types
and cataloging them based on certain geospatial attributes. All together, there are
hundreds of thousands of files on the drives. As part of the process, I'm currently using
the GetFiles method of the FileSystem object to retrieve collection of strings
representing a collection of a particular file type (for example, tif files). The problem
is that the GetFiles method doesn't seem to make any callbacks that would allow for me to
show some sort of meaningful progress, and the process can take a very long time. I know
I could fudge it with a marquee style progress bar and\or a busy mouse icon, but this
isn't ideal.
So, I was looking into using the API to do the grunt work. This would allow me to at
least display each filename in a label control as the search is being performed. I'm
trying to port Randy Birch's VB6 code available on his website at
http://vbnet.mvps.org/code/fileapi/r...l_multiple.htm . It's working
somewhat, except for the FindNextFile function which I've declared like so:
/////
Private Declare Function FindNextFile Lib "kernel32" _
Alias "FindNextFi leA" _
(ByVal hFindFile As Int32, _
ByVal lpFindFileData As WIN32_FIND_DATA ) As IntPtr
/////
As currently implemented, the function is not moving the search to the next file. It is
always returning the first file in the directory and it returns all the properties of that
file correctly. And it returns this first file for as many times as there are files in
the directory. I'm thinking it's because the WIN32_FIND_DATA - which is a UDT in the VB6
code - is defined as an object in my code and Dim'd as
/////
Dim WFD As WIN32_FIND_DATA = New WIN32_FIND_DATA
/////
at the beginning of the SearchForFiles Sub. For reference, in my code WIN32_FIND_DATA
defined like so:
/////
<StructLayout(L ayoutKind.Seque ntial, _
CharSet:=CharSe t.Auto)_
Friend Class WIN32_FIND_DATA
Friend sfileAttributes As Int32 = 0
Friend creationTime_lo wDateTime As Int32 = 0
Friend creationTime_hi ghDateTime As Int32 = 0
Friend lastAccessTime_ lowDateTime As Int32 = 0
Friend lastAccessTime_ highDateTime As Int32 = 0
Friend lastWriteTime_l owDateTime As Int32 = 0
Friend lastWriteTime_h ighDateTime As Int32 = 0
Friend nFileSizeHigh As Int32 = 0
Friend nFileSizeLow As Int32 = 0
Friend dwReserved0 As Int32 = 0
Friend dwReserved1 As Int32 = 0
<MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=MAX_ PATH)_
Friend fileName As String = Nothing
<MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=14)_
Friend alternateFileNa me As String = Nothing
End Class
/////
How can I make it so the FindNextFile call actually moves on to the next file in the
directory?
Lance