The GetFileSize function retrieves the size, in bytes, of the specified file. DWORD GetFileSize( HANDLE hFile, // handle of file to get size of LPDWORD lpFileSizeHigh // address of high-order word for file size ); ParametershFileSpecifies an open handle of the file whose size is being returned. The handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file. lpFileSizeHighPoints to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word.
//------------------------------------------------------------------------------ // // 取指定文件的大小 // // 参数 : // FileName : 指定的文件名(带路径) // // 返回值 : // 成功: 返回文件的大小 (单位 : KB) // 失败: 返回 -1 // //------------------------------------------------------------------------------ function GetFileSize(const FileName: String): LongInt; var F: File of Byte; begin //文件关联 AssignFile(F, FileName); Try Reset(F); //打开文件 Try //返回大小 KB Result := FileSize(F) DIV 1024; Finally; CloseFile(F); //关闭文件 end; Except; Result := -1; //失败 end; end;
改一下就可以满足你的要求function GetFileSize(const FileName: String): Boolean; var F: File of Byte; begin //文件关联 AssignFile(F, FileName); Try Reset(F); //打开文件 Try //返回大小 KB Result := FileSize(F) > (1024 * 1024 * > 20); Finally; CloseFile(F); //关闭文件 end; Except; Result := False; //失败 end; end;
LPDWORD lpFileSizeHigh // address of high-order word for file size
);
ParametershFileSpecifies an open handle of the file whose size is being returned. The handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file. lpFileSizeHighPoints to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word.
//
// 取指定文件的大小
//
// 参数 :
// FileName : 指定的文件名(带路径)
//
// 返回值 :
// 成功: 返回文件的大小 (单位 : KB)
// 失败: 返回 -1
//
//------------------------------------------------------------------------------
function GetFileSize(const FileName: String): LongInt;
var
F: File of Byte;
begin
//文件关联
AssignFile(F, FileName);
Try
Reset(F); //打开文件
Try
//返回大小 KB
Result := FileSize(F) DIV 1024;
Finally;
CloseFile(F); //关闭文件
end;
Except;
Result := -1; //失败
end;
end;
var
F: File of Byte;
begin
//文件关联
AssignFile(F, FileName);
Try
Reset(F); //打开文件
Try
//返回大小 KB
Result := FileSize(F) > (1024 * 1024 * > 20);
Finally;
CloseFile(F); //关闭文件
end;
Except;
Result := False; //失败
end;
end;
来骗分啊,呵呵......
function SearchFile( RootPath, FileName: String; var lstFile: TStrings ):Boolean;//---------------------------------------------------------------------------
//
// 查找一个目录下的文件,写在lstFile
//
//---------------------------------------------------------------------------
function SearchFile( RootPath, FileName :String; var lstFile: TStrings ):Boolean;
var
FileRec : TSearchRec;
begin
if RootPath[Length(RootPath)] <>'\' then
RootPath := RootPath +'\'; if ( FindFirst( RootPath + FileName, faAnyFile, FileRec ) =0 ) then
begin
lstFile.Add( RootPath + FileRec.Name );
while ( FindNext( FileRec ) = 0 ) do
begin
lstFile.Add( RootPath + FileRec.Name );
end;
end;
FindClose( FileRec ); Result := True;
end;使用方法:
var
lstFiles :TString;
begin
lstFiles := TStringList.Create;
SearchFile( 'C:\', *.*, lstFiles );
// c盘下的所有文件名称都在lstFiles中了。
// 文件名一就是:lstFiles.Strings[0];
// 文件名二就是:lstFiles.Strings[1];
end;