Sfile:=dlgOpenPic1.FileName;
      Nfile:=ExtractFilePath(Application.ExeName)+'DownLoadImg';
      if not CopyFile(PWideChar(Sfile),PWideChar(Nfile),False)=True then
      ShowMessage('error');以上语句复制文件,为什么不成功,总是ShowMessage('error')呢?      Sfile:=AnsiString(dlgOpenPic1.FileName);
      Nfile:=AnsiString(ApplicationPath+'DownLoadImg');
      if not CopyFileA(PAnsiChar(Sfile),PAnsiChar(Nfile),False)=True then
      ShowMessage('error');
换成这样也是一样的结果

解决方案 »

  1.   

    上面写错了
    if not CopyFileA(PAnsiChar(Sfile),PAnsiChar(Nfile),False)=True then
    改成
    if CopyFileA(PAnsiChar(Sfile),PAnsiChar(Nfile),False)=False then
     
      

  2.   

    试试这个
    var
      Sfile, Nfile, ApplicationPath: string;
    begin
      if dlgOpenPic1.Execute then
      begin
        ApplicationPath := ExtractFilePath(Application.ExeName);
        Sfile := (dlgOpenPic1.FileName);
        Nfile := (ApplicationPath + 'DownLoadImg');
        if CopyFile(pchar(Sfile), pchar(Nfile), false) = False then
          ShowMessage('error');
      end;
    end;
      

  3.   

    成功了的,新文件名是DownLoadImg没有扩展名????自己加上去
      

  4.   

    原因很简单啊,downloadimg文件已经存在。
     if not CopyFile(PWideChar(Sfile),PWideChar(Nfile),False)=True then改成如下:
     if CopyFile(PWideChar(Sfile),PWideChar(Nfile),true)=True then
    这样就可以了。
    另外:你的文件名没有扩展名啊?
      

  5.   

     if CopyFile(PWideChar(Sfile),PWideChar(Nfile),true) then