bsp; begin
MesString := '源数据库目录与目标数据库目录相同,系统不能进行备份。';
MessageBox(Handle, PChar(MesString), '错误', MB_OK + MB_ICONERROR);
end;
exit;
end;
// 检测目的路径是否存在
ShouldCopy := True;
if (DirectoryExists(DFilePath)) then
begin
if B_showmessage then
begin
MesString := '目的路径 ' + DFilePath + ' 已经存在,继续备份会删除该文件夹下的所有文件。' + chr(13) + '是否继续备份至该目录?';
if MessageBox(Handle, PChar(MesString), '信息', MB_YESNO + MB_ICONINFORMATION) <> IDYES then
ShouldCopy := False
else //先删除该文件夹
begin
OpStruc.wFunc := FO_DELETE;
StrPCopy(FromBuf, Pchar(DFilePath));
ShFileOperation(OpStruc);
goto COPYAGAIN; //删除已存在的目录文件夹后重新COPY
end;
end
else
begin
OpStruc.wFunc := FO_DELETE;
StrPCopy(FromBuf, Pchar(DFilePath));
ShFileOperation(OpStruc);
goto COPYAGAIN; //删除已存在的目录文件夹后重新COPY
end;
end;
if ShouldCopy then
begin
if ShFileOperation(OpStruc) <> 0 then
begin
MesString := '在备份目录' + SFilePath + '的过程中出现错误。';
MessageBox(Handle, PChar(MesString), '错误', MB_OK + MB_ICONERROR);
end
else // 将文件的属性设置为不是只读属性
begin
FileAttrs := faAnyFile;
if FindFirst(DFilePath + '\*.*', FileAttrs, sr) = 0 then
begin
FileSetAttr(DFilePath + '\' + sr.Name, faArchive);
end;
while FindNext(sr) = 0 do
begin
FileSetAttr(DFilePath + '\' + sr.Name, faArchive);
end;
FindClose(sr);
if B_showmessage then
begin
showmessage('所有数据已安全备份至“' + dfilepath + '”!');
self.Close;
end;
end;
end;
end;
procedure TBackUpForm.Edit_pathChange(Sender: TObject);
begin
if trim(Edit_path.Text) <> '' then
OKBtn.Enabled := true
else
OKBtn.Enabled := false;
end;
procedure TBackUpForm.FormCreate(Sender: TObject);
var
SourcePath: string