首页 > 解决方案 > Inno Setup RenameFile 和 FileCopy 在某些计算机上莫名其妙地失败

问题描述

我的应用程序有几千兆字节的图像数据,这些数据曾经存储在{app}目录中。在下一次更新中,作为 Inno Setup 安装的一部分,我需要将该图片数据移动到{commonappdata}目录中,以便成为一个表现良好的程序。

我创建了一个过程,该过程试图通过重命名(出于速度目的)来移动一个充满图像的目录(由InName参数标识)。如果失败(即,如果目录位于不同的驱动器上),则该过程将复制文件,然后删除源。

所有这些在我的计算机和我可以访问的任何计算机上都运行良好,但对于大多数其他人来说,它无法重命名目录,然后无法复制它。该过程记录了所有这些,因此我知道源名称和目标名称是正确的,但是 RenameFile 和 FileCopy 只是失败而没有任何解释。

我真的很感激任何人对为什么RenameFileandFileCopy命令在其他人的计算机上失败但不是我的计算机上的任何想法。我已经验证他们可以使用文件资源管理器复制文件而没有任何问题(它们不是只读的或类似的东西)。

Procedure MoveIt(InName: string);
var Sstr,Dstr: string;
begin
  Sstr:=ExpandConstant('{app}')+'\images\'+InName;
  Dstr:=ExpandConstant('{commonappdata}')+'\MyApp\images\'+InName;
  Log('Source: '+Sstr);
  Log('Destination: '+Dstr);
  if DirExists(Sstr) then
  begin
    OutputMsgMemoWizardPage.RichEditViewer.lines.add(InName+'...');
    if RenameFile(ExpandConstant('{app}')+'\images\'+InName,ExpandConstant('{commonappdata}')+'\MyApp\images\'+InName) then
    begin
      Log('Rename result=success');
      OutputMsgMemoWizardPage.RichEditViewer.lines[OutputMsgMemoWizardPage.RichEditViewer.lines.Count-1]:=InName+': success';
    end else
    begin
      Log('Rename result=Failed'); 
      if FileCopy(ExpandConstant('{app}')+'\images\'+InName,ExpandConstant('{commonappdata}')+'\MyApp\Folder images\'+InName,true) then
      begin
        Log('Copy result=success');
        OutputMsgMemoWizardPage.RichEditViewer.lines[OutputMsgMemoWizardPage.RichEditViewer.lines.Count-1]:=InName+': success';
        if DeleteFile(ExpandConstant('{app}')+'\images\'+InName) then
          Log('Delete result=success')
        else
        begin
          Log('Delete result=Failed');
          OutputMsgMemoWizardPage.RichEditViewer.lines.add(InName+
            '(Could not delete source directory)');
        end;
      end else
      begin
        Log('Copy result=Failed');
     OutputMsgMemoWizardPage.RichEditViewer.lines[OutputMsgMemoWizardPage.RichEditViewer.lines.Count-1]:=InName+': Failed';
      end;
    end
  end else Log('Source file not found');
end;

标签: installationinno-setuppascalscript

解决方案


确保目标目录确实存在。即那些喜欢{commonappdata}\MyApp\images.

RenameFilenorFileCopy函数不会为您创建它们。


您还可以GetLastError在功能失败后检查。有关声明,请参阅Inno Setup FileExists unable to find existing file


推荐阅读