Solved

Shileoperation with multiple destination

Posted on 2003-11-06
2
138 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

772 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