当Access文件被打开了的,或者正在被其他程序占用的情况下,如何进行复制?
谢谢大家!!!

解决方案 »

  1.   

    var
      MyFileName: string;
    begin
      MyFileName := '';
      try
      if dlgSave1.Execute then
      begin
        MyFileName := dlgSave1.FileName;
        if MyFileName <> '' then
        begin
          if CopyFile(Pchar(ExtractFilePath(Application.ExeName) + 'SmartCash.mdb'), Pchar(MyFileName), false) then
          begin
            Application.MessageBox('数据备份成功','提示',Mb_ok + mb_iconinformation);
          end;
        end;
      end;
      except
        Application.MessageBox('数据备份失败','提示',Mb_ok + mb_iconError);
      end;
    我测过,打开也能复制
    dlgSave1的缺省扩展名为MDB
      

  2.   

    To:elite01(极度) 
    不行啊,兄弟,你把你这段代码写在定时器里面,然后在复制之前加上删除
    DeleteFile('C:\Documents and Settings\fg.FUGANG\My Documents\temp\DB2005.mdb');
    你在测试一下就明白了,是不行的
      

  3.   

    正在用的时候怎么删除?除非你把正在用的MDB表关了再说
      

  4.   

    给你一个复制的代码!
    procedure NetFileCopy(SourceFile,MoveToFile:string;P:TRzProgressBar);
    var
      FromF, ToF: file;
      NumRead, NumWritten: Integer;
      Buf: array[1..2048] of Char;
    begin
        AssignFile(FromF, MoveToFile);
        Reset(FromF, 1); { Record size = 1 }    AssignFile(ToF,SourceFile); { Open output file }
        Rewrite(ToF, 1); { Record size = 1 }    P.PartsComplete:=0;
        P.TotalParts:=sizeof(FromF);
        repeat
            BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
            BlockWrite(ToF, Buf, NumRead, NumWritten);
            P.IncPartsByOne;
        until (NumRead = 0) or (NumWritten <> NumRead);
        CloseFile(FromF);
        CloseFile(ToF);
        P.PartsComplete:=0;
    end;
      

  5.   

    我是删除掉刚刚复制的那个
    DeleteFile('C:\Documents and Settings\My Documents\temp\SmartCash.mdb');
      

  6.   

    可能删除要一个时间,加上if DeleteFile(...)试试,或者要延时什么的