1.要注意大小写,那是个常量
2.可以用API findfirstfile
下面是关于 findfirstfile的说明(英文的)
Unit
Windows.Pas
Syntax
FindFirstFile(
lpFileName: PChar; {a pointer to a filename}
var lpFindFileData: TWin32FindData {a pointer to a TWin32FindData structure}
): THandle; {returns a search handle}
Description
This function searches the current directory for the first file that matches the filename specified by the lpFileName parameter. This function will find both files and subdirectories, and the filename being searched for can contain wild cards.
Parameter:
lpFileName: A pointer to a null terminated string containing the path and filename for which to search. This filename may contain wild cards .
lpFindFileData: A pointer to a TWin32FindData data structure containing information about the file or subdirectory that was found. The TWin32FindData data structure is defined as:
TWin32FindData = record
dwFileAttributes: DWORD; {file attributes}
ftCreationTime: TFileTime; {file creation time}
ftLastAccessTime: TFileTime; {last file access time}
ftLastWriteTime: TFileTime; {last file modification time}
nFileSizeHigh: DWORD; {high double word of file size}
nFileSizeLow: DWORD; {low double word of file size}
dwReserved0: DWORD; {reserved for future use}
dwReserved1: DWORD; {reserved for future use}
cFileName: array[0..MAX_PATH - 1] of AnsiChar; {long file name}
cAlternateFileName: array[0..13] of AnsiChar; {short file name}
end;
dwFileAttributes: Specifies the file attribute flags for the file. See the GetFileAttributes function for a list of possible file attribute flags.
ftCreationTime: Specifies the time that the file was created.
ftLastAccessTime: Specifies the time that the file was last accessed.
ftLastWriteTime: Specifies the time that the file was last modified.
nFileSizeHigh: Specifies the high order double word of the file size.
nFileSizeLow: Specifies the low order double word of the file size.
dwReserved0: This member is reserved for future use, and its value is undetermined.
dwReserved1: This member is reserved for future use, and its value is undetermined.
cFileName: A null terminated string containing the long version of the filename.
cAlternateFileName: A null terminated string containing the short (8.3) version of the filename.
Return Value
If the function succeeds, it returns a search handle that can be used in subsequent calls to FindNextFile. If the function fails, it returns INVALID_HANDLE_VALUE.
看不懂再说
function FileGetSize(FileName:string): Int64;
var w32fd: TWin32FindData; h: THandle;
begin
Result := 0;
if FileName='' then Exit;
h := Windows.FindFirstFile(PChar(FileName),w32fd);
if h <> INVALID_HANDLE_VALUE then
with w32fd do Result := nFileSizeHigh * MAXDWORD + nFileSizeLow;
Windows.FindClose(h);
end;