L
Lance
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/recursivefiles_minimal_multiple.htm . It's working
somewhat, except for the FindNextFile function which I've declared like so:
/////
Private Declare Function FindNextFile Lib "kernel32" _
Alias "FindNextFileA" _
(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(LayoutKind.Sequential, _
CharSet:=CharSet.Auto)> _
Friend Class WIN32_FIND_DATA
Friend sfileAttributes As Int32 = 0
Friend creationTime_lowDateTime As Int32 = 0
Friend creationTime_highDateTime As Int32 = 0
Friend lastAccessTime_lowDateTime As Int32 = 0
Friend lastAccessTime_highDateTime As Int32 = 0
Friend lastWriteTime_lowDateTime As Int32 = 0
Friend lastWriteTime_highDateTime As Int32 = 0
Friend nFileSizeHigh As Int32 = 0
Friend nFileSizeLow As Int32 = 0
Friend dwReserved0 As Int32 = 0
Friend dwReserved1 As Int32 = 0
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> _
Friend fileName As String = Nothing
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=14)> _
Friend alternateFileName 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
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/recursivefiles_minimal_multiple.htm . It's working
somewhat, except for the FindNextFile function which I've declared like so:
/////
Private Declare Function FindNextFile Lib "kernel32" _
Alias "FindNextFileA" _
(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(LayoutKind.Sequential, _
CharSet:=CharSet.Auto)> _
Friend Class WIN32_FIND_DATA
Friend sfileAttributes As Int32 = 0
Friend creationTime_lowDateTime As Int32 = 0
Friend creationTime_highDateTime As Int32 = 0
Friend lastAccessTime_lowDateTime As Int32 = 0
Friend lastAccessTime_highDateTime As Int32 = 0
Friend lastWriteTime_lowDateTime As Int32 = 0
Friend lastWriteTime_highDateTime As Int32 = 0
Friend nFileSizeHigh As Int32 = 0
Friend nFileSizeLow As Int32 = 0
Friend dwReserved0 As Int32 = 0
Friend dwReserved1 As Int32 = 0
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> _
Friend fileName As String = Nothing
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=14)> _
Friend alternateFileName 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