Solved

Shileoperation with multiple destination

Posted on 2003-11-06
2
140 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
[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 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Magic Software info 18 144
Create a path if not exists 7 108
Tvertscrollbox like a whatsapp layout delete messages 1 39
MS Access from Delphi 31 81
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…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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