读书人

Delphi2010 CopyFile解决思路

发布时间: 2012-04-17 15:06:33 作者: rapoo

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');
换成这样也是一样的结果

[解决办法]
试试这个

Delphi(Pascal) code
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

没有扩展名????自己加上去
[解决办法]
探讨
Sfile:=dlgOpenPic1.FileName;
Nfile:=ExtractFilePath(Application.ExeName)+'DownLoadImg';
if not CopyFile(PWideChar(Sfile),PWideChar(Nfile),False)=True then
ShowMessage('error……

读书人网 >.NET

热点推荐