Solved

Shileoperation with multiple destination

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
FMX StringGrid1->Canvas->FillRect Problem 3 169
Delphi 2 68
Press three keys together and trigger a function 3 60
CheckListBox usage 3 71
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…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 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