在线等待,怎样获得指定文件夹下的文件和文件夹的个数和名称

中伟视界科技 2003-08-20 06:30:52
同上
...全文
216 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
7259 2003-08-20
  • 打赏
  • 举报
回复
在edit1中输入时加上、\*.*,自己把程序改一下也行
7259 2003-08-20
  • 打赏
  • 举报
回复
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.
中伟视界科技 2003-08-20
  • 打赏
  • 举报
回复
两位上面网址进不去啊
mrtxc 2003-08-20
  • 打赏
  • 举报
回复
同意海天子
huojiehai 2003-08-20
  • 打赏
  • 举报
回复
自己改一下就行了
huojiehai 2003-08-20
  • 打赏
  • 举报
回复
你看看这个里面有公用函数可以做得到
http://expert.csdn.net/Expert/topic/1656/1656068.xml?temp=.3735315

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧