问题描述
我的应用有数 GB 的图像数据,这些数据曾经存储在 {app}
目录中。在下一次更新中,作为 Inno Setup 安装的一部分,我需要将该图片数据移动到 {commonappdata}
目录,以便成为一个表现良好的程序。
我创建了一个过程,该过程尝试通过重命名(出于速度目的)来移动一个充满图像的目录(由 InName
参数标识)。如果失败(即如果目录位于不同的驱动器上),则该过程将复制文件,然后删除源。
所有这些在我的电脑和我可以访问的任何电脑上都很好用,但对于大多数其他人来说,它无法重命名目录,也无法复制它。该过程记录了所有这些,所以我知道源名称和目标名称是正确的,但是 RenameFile 和 Filecopy 只是失败而没有任何解释。
我真的很感激任何人对为什么 RenameFile
和 Filecopy
命令在其他人的计算机上失败而不是我的计算机上的任何想法。我已经验证他们可以使用文件资源管理器复制文件而没有任何问题(它们不是只读的或类似的东西)。
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;
解决方法
确保目标目录确实存在。 IE。那些喜欢{commonappdata}\MyApp\images
。
RenameFile
和 FileCopy
函数不会为您创建它们。
您也可以在函数失败后检查GetLastError
。有关声明,请参阅 Inno Setup FileExists unable to find existing file。