AnsweredAssumed Answered

vrf Windows 2000 API

Question asked by g.nied on Dec 16, 2002
John,

to use these functions you have to do quite a big step into the system. It
is fast but I would recommend to have a look at the free microsoft
scripting runtime FileSystemObject. Perhaps this can solve your needs.
If not, here are some hints:

You need from Kernel32.dll:
long _stdcall GetLastError ()
long _stdcall FindClose (long hFindFile)
long _stdcall FindFirstFileA (char* lpFileName, int *lpFindFileData)
long _stdcall FindNextFileA (long hFindFile, int *lpFindFileData)

and as a helper:
long _stdcall lstrcpynA (char* lpString1, int *lpString2, long iMaxLength)


With FindFirstfileA you search for the first file that matches the
lpFileName string (eg: c:*.txt). As the second input use an Int32 array
with 80 elements (to hild the WIN32_FIND_DATA structure). The return value
might be -1 for an error or a file handle (hFindFile). You need this handle
for the subsequent calls to FindNextFileA and for closing the loop (with
FindClose) after an error or when the last item is read.
If the call was successful the WIN32_FIND_DATA (lpFindFileData) structure
(see below) is filled with data.

(Are you still tuned?)

Now you must decode your Int32 array. To get the FILETIME values to VEE
times I use the formula (2.^32*HighInt32+LowInt32)*100n+B where B is the
empiric time offset of 'Jan 01, 1601  01:00:00'.
To extract a string from the Int32 Array I use the kernel function
lstrcpynA: extract the string as an Int32 subarray (Name=A[11:75], since
260 chars = 65*Int32, and AlternateName= A[76:79])
then call lstrcpynA with an empty string of desired length as the first,
the subarray as second and the number of characters as third parameter.

Example:            ___________
formula(" "*65)----|           | ---
formula(A[11:75])--| lstrcpynA | --- (string comes out at second pin)
formula(65)--------|___________| ---

----------------------------------------------------------------------
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 Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type
MAX_PATH = 260
---------------------------------------------------------------


Easy, isn't it? *g*

        Georg Nied
   Software-Development
Hansestr.7 - 51149 Cologne
        Germany
Mail: info@gn-software.de

> I'm trying to use the Windows 2000 API functions FindFirstFileA and
> FindNextFileA
> to search for all files of a given extension e.g. *.txt.
>
> Has anyone had any experience of using this method, any help would be
> most grateful.
>
>
>
> Thanks
>
> John

---
You are currently subscribed to vrf as: rsb@soco.agilent.com
To subscribe send a blank email to "join-vrf@it.lists.it.agilent.com".
To unsubscribe send a blank email to "leave-vrf@it.lists.it.agilent.com".
To send messages to this mailing list,  email "vrf@it.lists.it.agilent.com". 
If you need help with the mailing list send a message to "owner-vrf@it.lists.it.agilent.com".

Outcomes