delphi下文件查找findfirst
来源:互联网 发布:淘宝客服搞笑欢迎语 编辑:程序博客网 时间:2024/05/16 06:59
FindFirst 是用来寻找目标目录下的第一个文件,
FindFirst函数在delphi帮助下的定义:
function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer;
其中有一句:FindFirst returns 0 if a file was successfully located
也就是说,当成功找到文件时,返回0.
function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer;
其中有一句:FindFirst returns 0 if a file was successfully located
也就是说,当成功找到文件时,返回0.
FindNext 则是寻找下一个
TSearchRec 是一个文件信息的纪录,当FindFirst返回SearchRec时,你可以通过SearchRec.Name获取文件名,以及SearchRec.Size获取文件大小等信息。
unit unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, StdCtrls, DBCtrls, Mask, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
countd,countf:integer;
implementation
{$R *.DFM}
procedure search(dir:string);
var
targetpath:string;{目标路径名}
sr:TsearchRec;
begin
{第一阶段:找出初始dir目录下的所有文件,其中dir变量值由edit1的Text属性确定}
targetpath:=extractfilepath(dir); {分解出目标路径名}
if findfirst(dir,faanyfile,sr)=0 then
repeat
if((sr.name<>'.')and(sr.name<>'..') {排除父目录和本目录两个假文件}
and((filegetattr(targetpath+sr.name)and fadirectory)<>fadirectory)) {只取文件}
then
begin
form1.memo1.Lines.Add(targetpath+sr.name);{在memo中添加找到的文件}
countf:=countf+1;
end
until findnext(sr)<>0;
if findfirst(dir,faanyfile,sr)=0 then
repeat
if((sr.name<>'.')and(sr.name<>'..')){排除父目录和本目录两个假文件}
and((filegetattr(targetpath+sr.name)and fadirectory)=fadirectory){排除文件}
then
begin
search(targetpath+sr.name+'\*.*');{递归调用}
form1.memo1.Lines.Add(targetpath+sr.name);
countd:=countd+1;
end
until findnext(sr)<>0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
countf:=0;
countd:=0;
memo1.Clear;{清除数据表memo字段内容}
search(Edit1.Text);{调用Search()函数}
MessageDlg('文件搜索完毕!',mtInformation,[mbOk],0);{结束提示}
showmessage('目录:'+inttostr(countd)+' 文件:'+inttostr(countf))
end;
end.
- delphi下文件查找findfirst
- DELPHI - FindFirst查找文件
- Linux下文件查找
- ubuntu下文件查找
- c语言下文件查找
- 常用linux下文件查找
- Linux 下文件查找(find)
- linux下文件的查找
- 文件查找FindFirst FindNext
- delphi 2010 获取目录下文件列表
- Delphi——FindFirst学习
- Delphi——FindFirst学习
- Delphi——FindFirst学习
- Linux下文件查找Find使用实例
- Linux环境下文件查找之----find
- php查找文件夹下文件内容
- c#查找相应目录下文件
- Linux查找目录下文件包含关键字
- php处理xml类
- 快速排序经典实现
- 通过依赖属性来实现自定义控件的属性
- suse Linux设置操作系统安装盘的iso文件为安装源安装mysql服务
- 升级vp8
- delphi下文件查找findfirst
- vc使用wmi例子
- NS3 -- 使用trace
- Linux usb驱动程序全注释
- Sql server c#扩展存储过程支持并行多线程运算
- Java编程中“为了性能”尽量要做到的一些地方
- dwz框架下刷新页面和表单
- 财务软件是企业信息化的基础
- ORA-15061 reported while doing a file operation with 11.1 or 11.2 ASM after PSU applied in database