Author: kray kray
Searching for files and get no problems when the size is greater than 2 gig
The FindFirstFile / FindNextFile / FindClose APIs are used for searching for
When using these APIs it is important to remember that failing to close a Find can
result in files or directories not being available for some operations (such as
deletes). This is because these APIs open a handle to the objects being searched,
and the operating system won't allow you to do certain things to an object as long
as an active handle to that object exists.
Also, the data structure used by these APIs contains string data, which is
terminated by null characters.
1 procedure TForm1.Button1Click(Sender: TObject);
2 var3 Handle: THandle;
4 s: string;
5 FD: WIN32_FIND_DATA;
6 begin7 s := 'c:\*.*';
8 Handle := FindFirstFile(pchar(s), fd);
9 if Handle <> INVALID_HANDLE_VALUE then10 begin11 Memo1.Lines.Add(fd.cFileName);
12 while FindNextFile(handle, fd) = True do13 Memo1.Lines.Add(fd.cFileName);
Finds the first file matching the wild file specifier. '*' can be used to match 0
or more characters, '?' for a single character. If there are no wild specifiers in
the string the function acts as a query for an explicit single file. The function
works for both files and folders.
The WIN32_FIND_DATA contains full information about the first matched file.
dwFileAttributes File attributes (see CreateFile)
ftCreationTime Time file created (see GetFileTime)
ftLastAccessTime Time file last accessed
ftLastWriteTime Time file last written to
nFileSizeHigh Most significant 32bits of file size(see GetFileSize)
nFileSizeLow Least significant 32bits of file size
dwReserved0 O.S. specific data
dwReserved1 O.S. specific data
cFileName File name with extension within the folder
cAlternateFileName Alternate shortened (8.3) form of name iff cFileName is not a
valid MSDOS name
The returned handle is passed to FindNextFile to get at the next matching file or
folder. When the scan is completed FindClose must be used to close the handle.
17 WIN32_FIND_DATA = record18 dwFileAttributes: DWORD;
19 ftCreationTime: TFileTime;
20 ftLastAccessTime: TFileTime;
21 ftLastWriteTime: TFileTime;
22 nFileSizeHigh: DWORD;
23 nFileSizeLow: DWORD;
24 dwReserved0: DWORD;
25 dwReserved1: DWORD;
26 cFileName: array[0..MAX_PATH - 1] of AnsiChar;
27 cAlternateFileName: array[0..13] of AnsiChar;
The file is an archive file. Applications use this value to mark files for
backup or removal.
The file or directory is compressed. For a file, this means that all of the data in
the file is compressed. For a directory, this means that compression is the default
for newly created files and subdirectories.
The file is a directory.
The file is hidden. It is not included in an ordinary directory listing.
The file has no other attributes set. This value is valid only if used alone.
The data of the file is not immediately available. Indicates that the file data has
been physically moved to offline storage.
The file is read-only. Applications can read the file but cannot write to it or
The file is part of the operating system or is used exclusively by it.
The file is being used for temporary storage. Applications should write to the file only if absolutely necessary. Most of the file's data remains in memory without being flushed to the media because the file will soon be deleted.