Solved

SHFileOperation - not displaying existing filename on copy

Posted on 2002-07-23
16
373 Views
Last Modified: 2010-04-04
Using W2K, when I use SHFileOperation to copy a file to a floppy, if the file exists, the window displays '' instead of 'filename'.
I am using the TFlyingOp component from Eric Pedrazzi, and need to copy all the zip files from one directory to a:\.

Other windows apps show the duplicate filename OK.

Any ideas anyone?
0
Comment
Question by:nigeltodd
[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
  • 6
  • 6
  • 2
  • +2
16 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 7171524
Add FOF_NOCONFIRMATION or FOF_NOERRORUI in fFlags. Not tested, just an idea.

Regards, Geo
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7171545
Try this:

procedure CopyFile(FileName, Destination: String);
var buffer: Array [0..1000] of Char;
    p: PChar;
    Fo: TSHFileOpStruct;
begin
  FillChar(Buffer, sizeof(Buffer), #0);
  p := @buffer;
  p := StrECopy(p, Pchar(FileName)) + 1;
  FillChar(Fo, sizeof(Fo), #0);
  With Fo do begin
       Wnd    := Application.Handle;
       wFunc  := FO_COPY;
       pFrom  := @Buffer;
       pTo    := Pchar(Destination);
       fFlags := FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
  end;
  SHFileOperation(Fo);
end;

// DEMO
// -------

procedure TForm1.Button1Click(Sender: TObject);
begin
  CopyFile(ExtractFilepath(Application.ExeName)+'unit1.pas', 'A:\');
end;


It will show you everything during a copy process, regardless of whether the file exist or not on A:\
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7171551
geobul was faster - if it works, he gets the points.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:geobul
ID: 7176903
Have you edited the text of the question? It sounds changed to me. You may also post a comment. It's actually the preferred (right?) way.

What is TFlyingOp component supposed to do?

If there is a name collision during the copy what will you want your app to do? Replacing the file without asking, ask the user what to do or something else?

Regards, Geo
0
 

Author Comment

by:nigeltodd
ID: 7178689
Yes, I have edited the question. TFlyingOp is a wrapper for ShFileOperation, which allows multiple files to be copied. I wish the program to ask what to do if a file exists.

The component is available from : http://www.delphi32.com/vcl/2632/download,xid,2632.asp



0
 
LVL 17

Expert Comment

by:geobul
ID: 7179762
The TFlyingOp component uses FOF_ALLOWUNDO or FOF_MULTIDESTFILES (or FOF_NOCONFIRMMKDIR if needed) flags and a list of source files which means that a windows standard 'File Replace Dialog' should be popped up. My Win2K Pro behaves that way. Renaming is not available.

You can modify 'procedure TFlyingOp.FExecuteOp(idOp : UINT);' or write some code yourself if you want another behaviour. For example:

// single file copy with dialogs for replacing and renaming
uses ShellApi;

procedure CopyFile(FileName, Destination: String);
var
  Fo: TSHFileOpStruct;
  NewFileName: string;
  sFrom, sTo: AnsiString;
  CopyYes: boolean;
begin
  NewFileName := Destination + ExtractFileName(FileName);
  CopyYes := true;
  while FileExists(NewFileName) do begin
    if MessageDlg('File '+ NewFileName + ' exists! Replace it?', mtConfirmation, [mbYes, mbNo], 0) = mrNo then begin
      if MessageDlg('Rename the file?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
        NewFileName := InputBox('Renaming file','Enter new filename:',NewFileName);
      end else begin
        CopyYes := false;
        Break;
      end;
    end else begin
      Break;
    end;
  end;
  if CopyYes then begin
    sFrom := FileName + #0;
    sTo := NewFileName + #0;
    With Fo do begin
      Wnd    := Application.Handle;
      wFunc  := FO_COPY;
      pFrom  := PChar(sFrom);
      pTo    := PChar(sTo);
      fFlags := FOF_NOCONFIRMATION;
    end;
    SHFileOperation(Fo);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CopyFile('c:\test.out', 'A:\');
end;

Regards, Geo
0
 

Author Comment

by:nigeltodd
ID: 7182793
I have double checked everyhting, and I still lose the actual; duplicate filename. Everything else is exactly as I would expect(and want!).

I think I may have to try another component, as the author has not responded to my email.

Regards,
Nigel
0
 

Author Comment

by:nigeltodd
ID: 7182860
I have double checked everyhting, and I still lose the actual; duplicate filename. Everything else is exactly as I would expect(and want!).

I think I may have to try another component, as the author has not responded to my email.

Regards,
Nigel
0
 

Author Comment

by:nigeltodd
ID: 7182998
I have rewritten a bit of code, and used the ShFileOperation function myself. It works fine for the copy(including showing dupe filenames), but if I use following code to delete the files, it always asks if I wiant ot delete files in Recycle Bin!

Any thoughts.


var bk1 : string;
    F : TShFileOpStruct;
begin
  bk1 := extractfilepath(application.exename) + 'Archives';
  fillchar(F, sizeof(F),0);
  F.Wnd := GetActiveWindow;
  F.wFunc := FO_DELETE;
  F.pFrom := PChar(bk1 + '\*.zip' + #0#0);
  F.fFlags := FOF_FILESONLY;
  if ShFileOperation(F) <> 0 then
    if F.fAnyOperationsAborted then
      MessageBox(F.Wnd,Pchar('Operation cancelled by      user'),nil,ID_OK)
    else
      MessageBox(F.Wnd,Pchar('The operation was unsuccessful'),nil,ID_OK);
end;
0
 
LVL 17

Expert Comment

by:geobul
ID: 7205657
Hi,

I'm sorry for the delay but I haven't received e-mail notifications.

try:
F.fFlags := FOF_FILESONLY or FOF_NOCONFIRMATION;

Regards, Geo
0
 

Author Comment

by:nigeltodd
ID: 7210935
adding FOF_NOCONFIRMATION does delete, without the flying window. Without NOCONFIRMATION, it asks "if I want to delete all files from the Recycle Bin?"

Seems weird. This is Win2K Professional, with D5.
0
 
LVL 17

Expert Comment

by:geobul
ID: 7211114
That's right. It asks but doesn't put the files in the Recycle Bin actually because there isn't FOF_ALLOWUNDO in the flags.

I'm not able to disable that stupid question and show the progress window in the same time. Sorry.

Regards, Geo
0
 

Author Comment

by:nigeltodd
ID: 7211996
What a &&^%#@%^A pain!!!

Thanks for your help anyway. If I do find out how to solve it, I'll let you know.
0
 

Expert Comment

by:CleanupPing
ID: 9343010
nigeltodd:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 17

Expert Comment

by:geobul
ID: 9361433
There was one question in the beginning (answered by me). The question was changed and I answered the second one also: there was no way.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9461474
nigeltodd,
No comment has been added lately (15 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to geobul http:#7171524

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
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…

738 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