备份文件小例: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;

解决方案 »

  1.   

    可以用Stream来做。
    =========================[I_am_zealot]=====
      

  2.   

    要是文件多的话,用一号楼长的方法,一两个的话,可以用stream。
      

  3.   

    我的一段以前的代码,可以供参考。screen.Cursor :=crHourGlass;
        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;