Solved

Possible to copy sub-directories?

Posted on 1998-01-07
2
153 Views
Last Modified: 2010-04-04
If I want to copy a whole directory including the sub-directories and the files there, how do I do it?
Is there a simple way?
I use Delphi Developer 2.0..

Thanx!
Erik N
0
Comment
Question by:Erik N
2 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 50 total points
ID: 1355601
The easiest way is to call the Windows 95 shell function ShFileOperation.  (Add ShellApi to your uses clause.)

E.g.  To copy C:\Test to C:\Temp, with a progress window:

procedure CopyDirs;
var
      FileOp: TSHFileOpStruct;
      sTo, sFrom: array[0..79] of Byte;
begin
      FillChar(FileOp, SizeOf(FileOp), 0);
      FileOp.Wnd := Self.Handle;
      FileOp.wFunc := FO_COPY;
      FillChar(sFrom, SizeOf(sFrom), 0);
      FillChar(sTo, SizeOf(sTo), 0);
      StrPCopy(@sFrom, 'C:\Test');
      StrPCopy(@sTo, 'C:\Temp');
      FileOp.pFrom := PChar(@sFrom);
      FileOp.pTo := PChar(@sTo);
      FileOp.fFlags := FOF_SIMPLEPROGRESS or FOF_RENAMEONCOLLISION or FOF_NOCONFIRMMKDIR;
      SHFileOperation(FileOp);
end;

The above example will copy C:\Test INTO C:\Temp, i.e. to C:\Temp\Test.
If you want to copy the contents of C:\Test into C:\Temp, i.e. C:\Test\Sub is copied to C:\Temp\Sub, change the following line
    StrPCopy(@sFrom, 'C:\Test');
to
    StrPCopy(@sFrom, 'C:\Test\*.*');


Regards,
JB
0
 

Author Comment

by:Erik N
ID: 1355602
Thank you JimBob, for this..

Erik N
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question