Solved

SHFileOperation - not displaying existing filename on copy

Posted on 2002-07-23
16
354 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
  • 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

22 Experts available now in Live!

Get 1:1 Help Now