Delphi2010 CopyFile
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');
换成这样也是一样的结果
[解决办法]
试试这个
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;
[解决办法]
成功了的,新文件名是DownLoadImg
没有扩展名????自己加上去
[解决办法]