Mega Code Archive

 
Categories / Delphi / Files
 

Files Bigger than 2 gig

Title: Files Bigger than 2 gig Question: Searching for files and get no problems when the size is greater than 2 gig Answer: The FindFirstFile / FindNextFile / FindClose APIs are used for searching for various files. 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. Example: procedure TForm1.Button1Click(Sender: TObject); var Handle:THandle; s:string; FD:WIN32_FIND_DATA; begin s:='c:\*.*'; Handle:=FindFirstFile(pchar(s), fd); if HandleINVALID_HANDLE_VALUE then begin Memo1.Lines.Add(fd.cFileName); while FindNextFile(handle, fd)=True do Memo1.Lines.Add(fd.cFileName); end; Windows.FindClose(Handle); end; 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. More Info: WIN32_FIND_DATA = record dwFileAttributes: DWORD; ftCreationTime: TFileTime; ftLastAccessTime: TFileTime; ftLastWriteTime: TFileTime; nFileSizeHigh: DWORD; nFileSizeLow: DWORD; dwReserved0: DWORD; dwReserved1: DWORD; cFileName: array[0..MAX_PATH - 1] of AnsiChar; cAlternateFileName: array[0..13] of AnsiChar; end; FILE_ATTRIBUTE_ARCHIVE The file is an archive file. Applications use this value to mark files for backup or removal. FILE_ATTRIBUTE_COMPRESSED 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. FILE_ATTRIBUTE_DIRECTORY The file is a directory. FILE_ATTRIBUTE_HIDDEN The file is hidden. It is not included in an ordinary directory listing. FILE_ATTRIBUTE_NORMAL The file has no other attributes set. This value is valid only if used alone. FILE_ATTRIBUTE_OFFLINE The data of the file is not immediately available. Indicates that the file data has been physically moved to offline storage. FILE_ATTRIBUTE_READONLY The file is read-only. Applications can read the file but cannot write to it or delete it. FILE_ATTRIBUTE_SYSTEM The file is part of the operating system or is used exclusively by it. FILE_ATTRIBUTE_TEMPORARY 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.