...
...
uses FileCtrl;
...
...
var
SearchRec: TSearchRec;
aList: TStringList;
BackUpDir: Stirng;
I: Integer;
begin
aList :=TStringList.Create;
BackUpDir :='';
try
aList.Clear;
aList.Sorted :=True;
if SelectDirectory('选择备份路径.','我的电脑',BackUpDir)and(BackUpDir<>'') then
begin
FindFirst(BackUpDir+'/*.*',faAnyFile,SearchRec);
if pos('.',SearchRec.Name)<>1 then // 防止无效文件名.
aList.Add(SearchRec.Name);
while FindNext(SearchRec)=0 do
begin
if pos('.',SearchRec.Name)<>1 then // 防止无效文件名.
aList.Add(SearchRec.Name);
end;
if aList.Items.Count >0 then
begin
for I:=0 to aList.Count -1 do
begin
if Pos('.db',aList)<>0 then
...
...
end;
end;
end;
finally
FindClose(SearchRec);// 如果这个地方错了那就是 CloseFind(SearchRec);
aList.Free;
end;
end;
//以上是查询文件;
//下面是备份文件
...
...
const
aFiles: array[0..2]of String =('File1','File2','File3');
var
I: Integer;
begin
...
...
if SelectDirectory('选择备份路径.','我的电脑',BackUpDir)and(BackUpDir<>'') then
begin
if not DirectoryExists(BackUpDir) then
ForceDirectories(BackUpDir); 建立一个不存在的文件夹;
for I :=0 to 2 do
CopyFile(pChar('C:/DatabaseName/'+aFiles),pchar(BackUpDir)+'/'+aFiles)
end;
end;