Solved

Possible to copy sub-directories?

Posted on 1998-01-07
2
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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