怎样打开一个一个打开文件夹下面的所有文件,然后处理。?

xmayxmei 2003-08-20 11:34:39
文件夹遍历。
...全文
38 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
XXSingle 2003-08-21
  • 打赏
  • 举报
回复
文件夹遍历,及文件查询..........
bluenightsky 2003-08-21
  • 打赏
  • 举报
回复
这是把查找到的文件添加到listview里

function Tform1.GetDirectoryName(Dir:String):String; //设置DIR
begin
if Dir[LengTh(Dir)]<>'\' then
Result:=Dir+'\'
else
Result:=Dir;
end;

procedure Tform1.FindFiles(APath:String); //查找主函数
var
FSearchRec,DsearchRec:TSearchRec;
FindResult:integer;
it:tlistitem;
fhandle:thandle;
hip:pointer;
filesize:longint;
/////////
tempstr:string;
function IsDirNotation(ADirName:String):Boolean;
begin
Result:=(ADirName='.') or(ADirName='..')or(ADirName='') ;
End;

begin
Apath:=GetDirectoryName(APath);
FIndResult:=FindFirst(APath+'*.*',faAnyFile+faHidden+faSysFile+FaReadonly,FsearchRec);
Try
while FindResult=0 do
begin
it:=listview1.Items.Add;
it.Caption:=extractfilename(APath+FSearchRec.Name); //把查找到的文件列出来
it.SubItems.Add(APath+FSearchRec.Name);
fhandle:=createfile(pchar(APath+FSearchRec.Name),GENERIC_READ,FILE_SHARE_READ,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
new(hip);
filesize:=GetFileSize(fhandle,hip);
dispose(hip);
it.SubItems.Add(inttostr(filesize));
//获得所选路径以下文件路径
//tempint:=pos(nowdir,copy(apath,pathpos,length(apath)-pathpos+1));
//tempstr:=copy(apath,tempint+pathpos,length(apath)-tempint-pathpos);
tempstr:=copy(apath,pathpos,length(apath)-pathpos+1);
it.SubItems.Add(selectpath+tempstr+it.Caption);
closehandle(fhandle);
FindResult:=FindNext(FSearchRec);
end;
FindReSult:=FindFirst(APath+'*.*',faDirectory,DSearchRec);
while FindResult=0 do
begin
if (DSearchRec.Attr{ and faDirectory)}=faDirectory) and not ISDirNotation(DSEarchRec.Name) then
FindFiles(APath+DsearchRec.Name);
FindResult:=FindNext(DsearchREc);
end;
Finally
FindClose(FSearchRec);
findclose(DsearchREc);
end;
end;

5,386

社区成员

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

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