我用这样的方式使用不对:CopyFile(oldPath,NewPath,False)不对,看帮助才知道Path是lp的,那应该怎么用呢?请高手指点,最好能给点代码see一下,多谢!

解决方案 »

  1.   

    CopyFile(Pchar(ExtractFilePath(Application.ExeName) + 'shoufa.mdb'), Pchar(MyFileName), false)
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      ErrorMessage: Pointer;      // holds a system error string
      ErrorCode: DWORD;           // holds a system error code
    begin
      {blank out the status bar}
      StatusBar1.SimpleText:='';  {attempt to copy the file}
      if not CopyFile(PChar(Edit1.Text+'\'+ExtractFilename(FileListBox1.FileName)),
                      PChar(Edit2.Text+'\'+ExtractFilename(FileListBox1.FileName)),                  not CheckBox1.Checked) then
      begin
        {if the file was not copied, display the error message}
        ErrorCode := GetLastError;
        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM,
                      nil, ErrorCode, 0, @ErrorMessage, 0, nil);
        StatusBar1.SimpleText:='Error Copying File: '+string(PChar(ErrorMessage));
        LocalFree(hlocal(ErrorMessage));
      end;
    end;The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
      

  3.   

    各位都使用的是CopyFile(Absoluteness Path, Nil)的格式,或者是CopyFile(PChar(A Path)...)的方法,但遗憾的是我使用的时候并不能完成复制的,返回的信息为Flase啊~~我是这样用的:  If not (FileExists('E:\software\password.txt')) Then
       ShowMessage('No File here');
        If not (CopyFile(PChar('E:/software/password.txt'),PChar('c:/temp/'),True)) Then
          ShowMessage('Copy File False');我每次得到的信息都是Copy File Fase 我汗````查看帮助,得到的CopyFile函数是这样的:BOOL CopyFile(
        LPCTSTR lpExistingFileName, // pointer to name of an existing file 
        LPCTSTR lpNewFileName, // pointer to filename to copy to 
        BOOL bFailIfExists  // flag for operation if file exists 
       );也就是说这里不是需要地址,而是指针?? 这个指针怎么得到呢?感谢各位的帮助,问题还没有搞定~~~再次麻烦各位了
      

  4.   

    uses shellapi;
    var tmp:string; //全局变量
    function WinCOPY(SourceFileName: String; TargetFileName: String): String;
    var
      OpStruc: TSHFileOpStruct;
      FromBuf,ToBuf: Array[0..128] of Char;
      opstr, Wnd:integer;
    begin
      FillChar(FromBuf,Sizeof(FromBuf),0);
      FillChar(ToBuf,Sizeof(ToBuf),0);
      //用0初始化FromBuf和ToBuf数组
      StrPCopy(FromBuf,Pchar(SourceFileName));
      StrPCopy(ToBuf,Pchar(TargetFileName));
      //分别在 FromBuf和ToBuf数组中填入操作的源目录及目标目录
      //开始填充OpStruc记录
      with OpStruc do
      begin
       // Wnd:=Handle;
        wFunc:=FO_COPY;
        //复制操作
        pFrom:=@FromBuf;
        pTo:=@ToBuf;
        fFlags:=FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
        fAnyOperationsAborted:=False;
        hNameMappings:=nil;
        lpszProgressTitle:=nil;
        OpStR:= SHFileOperation(OpStruc);
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
     if OpenDialog1.Execute then
     tmp:=OpenDialog1.FileName;
     if SaveDialog1.Execute then
     WinCOPY(tmp,(SaveDialog1.FileName+ExtractFileExt(OpenDialog1.FileName)));
     showmessage('文件复制成功!');
     end;