How to copy multiple files and use a wildcard

Any ideas why this isn't working? No errors, my text files just aren't copied.

procedure TForm1.CopyFiles(Source, Target: string);
var
FO: TShFileOpStruct;
begin
   FillChar(FO,SizeOf(FO),#0);
   FO.Wnd := Form1.Handle;
   FO.wFunc := FO_COPY;
   FO.pFrom := PChar(Source);
   FO.pTo := PChar(Target);
   ShFileOperation(FO);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
    CopyFiles('c:\test\*.txt','c:\test2\');
end;

      

+3


source to share


1 answer


You have no errors because you are not checking the return value of the call to SHFileOperation

. There may be an error, but you cannot know about it because you neglect to check it.

Another problem you are having is that you were unable to double the null, terminate the strings as stated in the documentation. So like this:



FO.pFrom := PChar(Source + #0);
FO.pTo := PChar(Target + #0);

      

Given these mistakes you've made, I suggest you read the documentation again.

+4


source