Board index » delphi » Please, oh please ShFileOperation - The file mapping object

Please, oh please ShFileOperation - The file mapping object

what the heck do you do with that pointer once you've got it?

Begging and begging........

 

Re:Please, oh please ShFileOperation - The file mapping object


Quote
Jill Marquiss wrote:

> what the heck do you do with that pointer once you've got it?

> Begging and begging........

Something like this I guess

uses ShellAPI;
procedure TForm1.FormCreate(Sender: TObject);
var
  shfo: TSHFileOpStruct;
begin
  shfo.Wnd := Handle;
  shfo.wFunc := FO_COPY;
  shfo.pFrom := 'c:\temp\sweep.log';
  shfo.pTo := 'c:\temp\sweep.log.copy';
  shfo.fFlags := FOF_SILENT;

  // Copy  sweep.log to sweep.log.copy
  if SHFileOperation(shfo) <> 0 then
    ShowMessage('Error');
end;

Re:Please, oh please ShFileOperation - The file mapping object


Nah....
I have copy, move, delete et all working
ShFileOperation allows you (supposedly) to set a flag
saying you want automatic rename on collision of a copy or move.

If that happens, the is another flag that says Windows should provide
a file mapping object so you can figure out what just happened to your
file name.

Like I say copy "fred" to a directory that already contains "fred".  If
I have automatic rename on, then I will get "copy of fred".  I'm also
supposed to get a pointer to a "file mapping object" which contains
"copy of fred" as being the new name of the file I copied.

The trouble is that if I send want mapping handle, I don't think I ever
get one.  Pointer is always nil.  

Re:Please, oh please ShFileOperation - The file mapping object


Quote
>Nah....
>I have copy, move, delete et all working

Could you email or post me a working example - I cannae get it to go
and I daont know why - get a EAccessViolation and I don't see where.

Thanks,
        Me.

Re:Please, oh please ShFileOperation - The file mapping object


Quote
On Tue, 11 Mar 1997 04:22:17 GMT, mar...@ihug.co.nz wrote:
>>Nah....
>>I have copy, move, delete et all working

>Could you email or post me a working example - I cannae get it to go
>and I daont know why - get a EAccessViolation and I don't see where.

>Thanks,
>    Me.

I just worked through the same problem. The best solution I have found
is to enter values for all the fields in the record.

Example

procedure Tform1.Button1Click(Sender: TObject);
var
  filename : string;
  pfile : pchar;
  shfile : tshfileopstruct;
begin
  filename:=filelistbox1.filename;
  strpcopy(pfile , filename);
  shfile.Wnd := Handle;
  shfile.wFunc := FO_DELETE;
  shfile.pFrom := pfile;
  shfile.pTo := nil;
  shfile.fFlags := FOF_ALLOWUNDO;
  shfile.fAnyOperationsAborted := false;
  shfile.hNameMappings := nil;
  shfile.lpszProgressTitle := nil;
  if SHFileOperations(shfile) <> 0 then ShowMessage('Delete Failed');
end;

It is real similar for copy and move.

Other Threads