2017-09-26 72 views
1

这是一个类似问题Find the path of an application, and copy a file to that directory in Inno Setup查找所有的应用程序文件夹,并安装有一个文件在Inno Setup的

我想将文件安装到Inno Setup的用户的MATLAB文件夹。但取决于MATLAB的版本,目录可能会更改,并且根据安装的版本数量,可能会有多个目标。

在Windows命令行,就可以得到MATLAB可执行的,像这样的路径:

where matlab 

将输出

C:\Program Files (x86)\MATLAB\R2015b\bin\matlab.exe 
C:\Program Files\MATLAB\R2017a\bin\matlab.exe 

的输出“其中”显示两个路径,因为安装了两个版本的MATLAB。我想将文件复制到以下文件夹中:

C:\Program Files (x86)\MATLAB\R2015b\bin 
C:\Program Files\MATLAB\R2017a\bin 

这怎么办?

回答

1

Inno安装程序无法将文件自行安装到随机数目的目标文件夹。

你必须一切帕斯卡尔脚本代码:

[Files] 
Source: "MyFile.dat"; Flags: dontcopy 

[Code] 

procedure ExtractFileToPathsWhereAnotherFileIs(ExtractFile: string; SearchFile: string); 
var 
    P: Integer; 
    Paths: string; 
    Path: string; 
    TempPath: string; 
begin 
    { Extract the file to temporary location (there's no other way) } 
    ExtractTemporaryFile(ExtractFile); 
    TempPath := ExpandConstant('{tmp}\' + ExtractFile); 

    Paths := GetEnv('PATH'); 
    { Iterate paths in PATH environment variable... } 
    while Paths <> '' do 
    begin 
    P := Pos(';', Paths); 
    if P > 0 then 
    begin 
     Path := Trim(Copy(Paths, 1, P - 1)); 
     Paths := Trim(Copy(Paths, P + 1, Length(Paths) - P)); 
    end 
     else 
    begin 
     Path := Trim(Paths); 
     Paths := ''; 
    end; 

    { Is it the path we are interested in? }  
    if FileExists(AddBackslash(Path) + SearchFile) then 
    begin 
     Log(Format('Found "%s" in "%s"', [SearchFile, Path])); 
     { Install the file there } 
     if FileCopy(TempPath, AddBackslash(Path) + ExtractFile, False) then 
     begin 
     Log(Format('Installed "%s" to "%s"', [ExtractFile, Path])); 
     end 
     else 
     begin 
     MsgBox(Format('Failed to install "%s" to "%s"', [ExtractFile, Path]), 
       mbError, MB_OK); 
     end; 
    end; 
    end; 
end; 

procedure CurStepChanged(CurStep: TSetupStep); 
begin 
    if CurStep = ssInstall then 
    begin 
    ExtractFileToPathsWhereAnotherFileIs('MyFile.dat', 'matlab.exe'); 
    end; 
end; 
相关问题