N
N
Notice_n2021-10-13 10:40:04
Delphi
Notice_n, 2021-10-13 10:40:04

How to leave the original folder name when copying?

When copying a folder, the copied folder is renamed according to the "name + path" type. How can I make sure that the folder name remains the same when copying?

procedure CopyFiles(const FromFolder: string; const ToFolder: string);
var
  Fo      : TSHFileOpStruct;
  buffer  : array[0..4096] of char;
  p       : pchar;
begin
  FillChar(Buffer, sizeof(Buffer), #0);
  p := @buffer;
  StrECopy(p, PChar(FromFolder));
  FillChar(Fo, sizeof(Fo), #0);
  Fo.Wnd    := Application.Handle;
  Fo.wFunc  := FO_COPY;
  Fo.pFrom  := @Buffer;
  Fo.pTo    := PChar(ToFolder);
  Fo.fFlags := FOF_NOCONFIRMATION;
  if ((SHFileOperation(Fo) <> 0) or (Fo.fAnyOperationsAborted <> false)) then
    ShowMessage('File copy process cancelled')
end;

procedure Form.BitBtn1Click(Sender: TObject);
begin
CopyFiles((Edit1.Text),(Edit3.Text));
ShowMessage('Папка успешно скопирована!');
end;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2021-10-13
@tsklab

Use the ShellFoldersBrowse component (listed below) to find the source folder and destination folder. To the last add ExtractFileNamefrom the source. Copy with System.IOUtils.TDirectory.Copy.
DELPHI+ShellFoldersBrowse . If nothing suits me, I can put my version here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question