//uses節にShellAPIを追加
uses ShellAPI;
procedure TForm1.Button1Click(Sender: TObject);
var
ExePath: String;
foStruct: TSHFileOpStruct;
begin
//アプリケーションパスの取得
ExePath := ExtractFilePath(Application.ExeName);
//バックアップフォルダの存在確認 無ければ作成
if not DirectoryExists(ExePath + '\backup') then
CreateDir(ExePath + '\backup');
//コピー
with foStruct do
begin
wnd := handle;
wFunc := FO_COPY; pFrom := PChar(ExePath + '\*' + #0#0);
pTo := PChar(ExePath + '\backup\' + #0#0);
fFlags := FOF_FILESONLY or FOF_NOCONFIRMATION or
FOF_SILENT;
fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
end;
SHFileOperation(foStruct);
end; |