Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browsing dir. structure recursively 1

Status
Not open for further replies.

TheBugSlayer

Programmer
Sep 22, 2002
887
US
Hello.

I need to be able to browse through the nodes of a directory structure and process all the zip files in it. Can anyone remind me how I can achieve that in Delphi? I am thinking maybe a hidden directory list box could help...

I have a DVD which contains data many zip files in many folders. This is a level one tree, only one level of leaves.

Thanks.
 
Your code could look something like this recursive procedure:
Code:
procedure ProcessAllZipFiles ( path: string );
var
 tsr: TSearchRec;
begin
 path := IncludeTrailingBackSlash ( path );
 if FindFirst ( path + '*', faAnyFile, tsr ) = 0 then begin
  repeat
   if ( tsr.attr and faDirectory ) > 0 then begin
    if ( tsr.name <> '.' ) and ( tsr.name <> '..' ) then
     ProcessAllZipFiles ( path + tsr.name );
   end
   else
    ProcessZipFile ( path + tsr.name );
  until FindNext ( tsr ) <> 0;
  FindClose ( tsr );
 end;
end;
You will need to write a ProcessZipFile procedure to actually process an individual zip file.

So for example, if you want to process all the zip files in your c:\data folder then you would call the above procedure as follows:
Code:
  ProcessAllZipFiles ( 'c:\data' );


Andrew
Hampshire, UK
 
Towercase,
Five stars. That was great! I will adapt it to my needs.

I think I have become a lazy programmer. I am trying to move into management...

Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top