Re: Copy directory

Posted by webmaster Guido on January 14, 2005

In Reply to: Copy directory posted by lucian5 on January 10, 2005

: How would i copy an entire directory in delphi. copyfile will not work cause you need to know the pathname. is there a way!

1. Collect all the pathnames into a stringlist. On DelphiLand you can find a source code example in the "Code Snips" section, under "Find Files Recursively".

2. Traverse the stringlist and copy all the files. A rough example, needs some polishing:

for i := 0 to SL.Count do begin
  Source := SL.Items[i];
  Destination := ... // make up the destination 
  CopyFile(PChar(Source), PChar(Destination),...);
end;

[ Delphi Forum and Tutorials ]