备份文件小例:var
p : SHFILEOPSTRUCT ;
str : string;
begin
str:=GetCurrentDir();
p.pFrom :=pchar(str+'\*.*');
showmessage(p.pFrom);
p.pTo :=pchar(str+'\backup\');
showmessage(p.pTo);
p.wFunc :=FO_COPY;
p.Wnd :=Handle;
p.lpszProgressTitle:= '请等待...';
{设定操作选项}
p.fFlags:= FOF_ALLOWUNDO or FOF_NOCONFIRMMKDIR
or FOF_NOCONFIRMATION or FOF_FILESONLY ;
try
SHFileOperation(p);
except
messagedlg('备份文件出错!',mtError,[mbOk],0);
exit;
end;end;
p : SHFILEOPSTRUCT ;
str : string;
begin
str:=GetCurrentDir();
p.pFrom :=pchar(str+'\*.*');
showmessage(p.pFrom);
p.pTo :=pchar(str+'\backup\');
showmessage(p.pTo);
p.wFunc :=FO_COPY;
p.Wnd :=Handle;
p.lpszProgressTitle:= '请等待...';
{设定操作选项}
p.fFlags:= FOF_ALLOWUNDO or FOF_NOCONFIRMMKDIR
or FOF_NOCONFIRMATION or FOF_FILESONLY ;
try
SHFileOperation(p);
except
messagedlg('备份文件出错!',mtError,[mbOk],0);
exit;
end;end;
=========================[I_am_zealot]=====
myfileList := TStringList.Create;
testList := TStringList.Create;
allfileList(myfileList,'数据库');//取得数据库目录下所有文件
forceDirectories(dir);
try
for i:=1 to myfileList.Count-1 do
begin
copyfile(pchar(mydatabase+'\'+myfileList[i]),pchar(dir+'\'+myfileList[i]),false);
testList.Add(myfileList[i]); //用于判断是否复制文件成功;
end;
except if MessageBox(handle,'数据库文件备份出现意外!',pchar('数据库备份失败'),mb_IconInformation)=mrYes then beep;
end;
copyOk:= (DirectoryExists(Dir)) and (myfileList=myfileList);
if copyOk then if MessageBox(handle,'数据库文件备份成功!',pchar('数据库备份'),mb_IconInformation)=mrYes then beep;
if copyok then
begin
searchDirectory(ExtractFileDir(Application.Exename)+'\backup\'); //在backuComboBox上添加子目录。
backupNewday;
end;
//if not copyOk then if MessageBox(handle,'数据库文件备份出现意外!',pchar('数据库备份失败'),mb_IconInformation)=mrYes then beep;
screen.Cursor :=crDefault;procedure TForm1.allfileList(files: TstringList;subDirector:string);
var
iFindResult: integer;
SearchRec: TSearchRec;
begin
files.Clear ;
iFindResult := FindFirst(ExtractFileDir(Application.Exename)+'\'+subDirector+'\*.*', faAnyFile, SearchRec);
while iFindResult = 0 do
begin
files.Add(SearchRec.Name);
iFindResult := FindNext(SearchRec);
end;
FindClose(SearchRec);
end;