nigeltodd
asked on
SHFileOperation - not displaying existing filename on copy
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
geobul was faster - if it works, he gets the points.
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
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
ASKER
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
The component is available from : http://www.delphi32.com/vcl/2632/download,xid,2632.asp
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
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
begin
CopyFile('c:\test.out', 'A:\');
end;
Regards, Geo
ASKER
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
I think I may have to try another component, as the author has not responded to my email.
Regards,
Nigel
ASKER
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
I think I may have to try another component, as the author has not responded to my email.
Regards,
Nigel
ASKER
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(applicatio n.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('Op eration cancelled by user'),nil,ID_OK)
else
MessageBox(F.Wnd,Pchar('Th e operation was unsuccessful'),nil,ID_OK);
end;
Any thoughts.
var bk1 : string;
F : TShFileOpStruct;
begin
bk1 := extractfilepath(applicatio
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('Op
else
MessageBox(F.Wnd,Pchar('Th
end;
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
I'm sorry for the delay but I haven't received e-mail notifications.
try:
F.fFlags := FOF_FILESONLY or FOF_NOCONFIRMATION;
Regards, Geo
ASKER
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.
Seems weird. This is Win2K Professional, with D5.
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
I'm not able to disable that stupid question and show the progress window in the same time. Sorry.
Regards, Geo
ASKER
What a &&^%#@%^A pain!!!
Thanks for your help anyway. If I do find out how to solve it, I'll let you know.
Thanks for your help anyway. If I do find out how to solve it, I'll let you know.
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.
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.
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.
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
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
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
begin
CopyFile(ExtractFilepath(A
end;
It will show you everything during a copy process, regardless of whether the file exist or not on A:\