this slowpoke moves

Rename File

uses ExtCtrls, ShellApi

//

function RenameFileEx(const AOldName, ANewName: string;
   ARenameCheck: boolean = false): boolean;
var
  sh: TSHFileOpStruct;
begin
  sh.Wnd := Application.Handle;
  sh.wFunc := fo_Move;

  // String must be terminated with #0 to set the end of the list
  sh.pFrom := PChar(AOldName + #0);
  sh.pTo := PChar(ANewName + #0);
  sh.fFlags := fof_Silent or fof_MultiDestFiles;
  if ARenameCheck then
    sh.fFlags := sh.fFlags or fof_RenameOnCollision;
  Result := ShFileOperation(sh) = 0;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
   RenameFileEx('c:\a1.txt',  // Original Datei
                'c:\a2.txt',  // Umbenannte Datei
                false);
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate