Solved

Shileoperation with multiple destination

Posted on 2003-11-06
2
136 Views
Last Modified: 2010-04-05
Hi, i have a code here but i have a problem.. I want to copy the files in a multiple directory in drive a but it only copy the first 'a:\backup' and the remaining is not copied..

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,shellApi;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  F:Tshfileopstruct;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
 sr:Tsearchrec;
 dir:string;
begin

  dir := 'a:\backup'+#0#0+'a:\backup3'+#0#0;
  if FindFirst('c:\backup3\*.zip',faAnyFile,sr) = 0 then
  begin
     if MessageDlg('Please insert diskette in dirve A:\', mtInformation, [mbOK,mbCancel],0) =  mrOk then
     begin
       F.wnd := handle;
       F.wfunc := FO_COPY;
       F.pfrom := pchar('c:\Backup3\*.zip');
       F.pto := pchar(dir);
       F.hNameMappings := NIL;
       F.Fflags := FOF_MULTIDESTFILES OR FOF_NOCONFIRMATION OR FOF_NOCONFIRMMKDIR;
       if shfileoperation(F) <> 0 then
          showmessage('File was not copied')
       else
          showmessage('File successfully copied.. Please Remove diskette in Drive A:\');
       end;
  end
  else
   showmessage('No files found in the backup3 folder...');

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
     Application.Terminate;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
    button2.SetFocus;
end;

end.
0
Comment
Question by:orafans
2 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9693115
i guess

this
dir := 'a:\backup'+#0#0+'a:\backup3'+#0#0;
 
must be
dir := 'a:\backup'+#0+'a:\backup3'+#0#0;

but just a guess

meikl ;-)
 
0
 
LVL 5

Accepted Solution

by:
snehanshu earned 250 total points
ID: 9693399
From
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarvb4/html/msdn_fileopen.asp

FOF_MULTIDESTFILES Tells the SHFileOperation function that the pTo field specifies multiple destination files. In other words, each source file has a corresponding destination file. Otherwise, the files will be copied or moved to a single directory.

I think this needs to have a one to one correspondence.
So, if your pfrom is 'C:\Folder1\File1.txt'+#0+'C:\Folder2\File2.txt'+#0#0
then you can set pto to
'a:\Folder1\File1.txt'+#0+'a:\Folder2\File2.txt'+#0#0

But it is not to copy one file to many locations. (only for n Different files to n different locations)

That's my understanding.
...Shu
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

23 Experts available now in Live!

Get 1:1 Help Now