Unit: SysUtils
Delphi 语法:
function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer;
FindFirst函数查找由Path参数指定的目录中的第一个匹配Path中隐含的文件名并且符合Attr参数属性的文件,由参数F将结果返回。如果成功找到文件FindFirst函数将返回0,否则返回一个错误码。
Path中可以使用通配符,例如'.\test\*.*'
Attr参数是常量枚举,可以有下列值:
Constant Description
faReadOnly Read-only files
faHidden Hidden files
faSysFile System files
faVolumeID Volume ID files
faDirectory Directory files
faArchive Archive files
faAnyFile Any file
Delphi中属性可以相加,例如查找只读且隐藏文件使用faReadOnly + faHidden
注意:FindFirst分配的资源必须使用FindClose释放掉。
----------------------------------------------------------------------------------------
功能说明:删除指定的文件。该函数只有一个参数。此参数为欲删除文件的完整路径。如果删除成功,则返回True。若删除失败、或文件不存在则返回False。
参考实例:
var
IsOK: Boolean; // 用于保存删除状态
begin
IsOK := DeleteFile('C:\My Documents\Index.html'); // 函数执着后,将结果返回给IsOK变量。如果IsOK变量为True,则表示文件删除成功。
if IsOK then ShowMessage('文件删除成功!')
else ShowMessage('文件删除失败!');
end;
Delphi 语法:
function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer;
FindFirst函数查找由Path参数指定的目录中的第一个匹配Path中隐含的文件名并且符合Attr参数属性的文件,由参数F将结果返回。如果成功找到文件FindFirst函数将返回0,否则返回一个错误码。
Path中可以使用通配符,例如'.\test\*.*'
Attr参数是常量枚举,可以有下列值:
Constant Description
faReadOnly Read-only files
faHidden Hidden files
faSysFile System files
faVolumeID Volume ID files
faDirectory Directory files
faArchive Archive files
faAnyFile Any file
Delphi中属性可以相加,例如查找只读且隐藏文件使用faReadOnly + faHidden
注意:FindFirst分配的资源必须使用FindClose释放掉。
----------------------------------------------------------------------------------------
功能说明:删除指定的文件。该函数只有一个参数。此参数为欲删除文件的完整路径。如果删除成功,则返回True。若删除失败、或文件不存在则返回False。
参考实例:
var
IsOK: Boolean; // 用于保存删除状态
begin
IsOK := DeleteFile('C:\My Documents\Index.html'); // 函数执着后,将结果返回给IsOK变量。如果IsOK变量为True,则表示文件删除成功。
if IsOK then ShowMessage('文件删除成功!')
else ShowMessage('文件删除失败!');
end;