在线等待,怎样获得指定文件夹下的文件和文件夹的个数和名称 同上 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你看看这个里面有公用函数可以做得到http://expert.csdn.net/Expert/topic/1656/1656068.xml?temp=.3735315 unit unit1;interfaceuses 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. 在edit1中输入时加上、\*.*,自己把程序改一下也行 如何让光标从dbgrid1跳至dbgrid2? 请教关于QQ界面可以自由变色的问题!!! 如何在DELPHI中调用C++写的数据库引擎?各位帮帮忙:) TADODataset状态问题 vc写的dll在delphi中调用,(数据类型的难题)100 TreeView控件问题:为什么执行下面一段代码之后,TreeView控件会有闪烁的现象??? 数据的为什么不可以更新? 如何重画Form的标题栏,或按钮等? delphi安装问题!Who can help me?在线等候! 用什么工具作安装盘比较好?:) 请教 用ClientDataSet存取Bolb字段!! 初学者问题
http://expert.csdn.net/Expert/topic/1656/1656068.xml?temp=.3735315
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.