首页  编辑  

查找所有文件

Tags: /超级猛料/Stream.File.流、文件和目录/文件操作/   Date Created:

procedure findall(disk,path: String; var fileresult: Tstrings);

var

fpath: String;

fs: TsearchRec;

begin

fpath:=disk+path+'\*.*';

if findfirst(fpath,faAnyFile,fs)=0 then

begin

if (fs.Name<>'.')and(fs.Name<>'..') then

if (fs.Attr and faDirectory)=faDirectory then

findall(disk,path+'\'+fs.Name,fileresult)

else

fileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(

strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');

while findnext(fs)=0 do

begin

if (fs.Name<>'.')and(fs.Name<>'..') then

if (fs.Attr and faDirectory)=faDirectory then

findall(disk,path+'\'+fs.Name,fileresult)

else

fileresult.add(disk+strpas(strupper(pchar(path)))+'\'+str

pas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');

end;

end;

findclose(fs);

end;

procedure DoSearchFile ( Path : string ; Files : TStrings = nil );

var

 Info : TSearchRec ;

  procedure ProcessAFile ( FileName : string );

  begin

    if Assigned ( PnlPanel ) then

     PnlPanel . Caption := FileName ;

   Label2 . Caption := FileName ;

  end ;

  function IsDir : Boolean ;

  begin

    with Info do

     Result := ( Name <> '.' ) and ( Name <> '..' ) and (( attr and fadirectory ) = fadirectory );

  end ;

  function IsFile : Boolean ;

  begin

   Result := not (( Info . Attr and faDirectory ) = faDirectory );

  end ;

begin

 Path := IncludeTrailingBackslash ( Path );

  try

    if FindFirst ( Path + '*.*' , faAnyFile , Info ) = 0 then

      if IsFile then

       ProcessAFile ( Path + Info . Name )

      else if IsDir then DoSearchFile ( Path + Info . Name );

    while FindNext ( Info ) = 0 do

    begin

      if IsDir then

       DoSearchFile ( Path + Info . Name )

      else if IsFile then

       ProcessAFile ( Path + Info . Name );

     Application . ProcessMessages ;

      if QuitFlag then Break ;

     Sleep ( 100 );

    end ;

  finally

   FindClose ( Info );

  end ;

end ;