Solved

Possible to copy sub-directories?

Posted on 1998-01-07
2
149 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now