首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

Delphi2010 CopyFile解决思路

2012-04-17 
Delphi2010 CopyFileSfile:dlgOpenPic1.FileNameNfile:ExtractFilePath(Application.ExeName)+DownLoa

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……

热点排行