削减路径的特定部分

时间:2017-06-18 18:34:41

标签: string inno-setup pascalscript

以下是Inno Setup的代码

function GetDirName(const Value: string): string;
    var 
    InstallPath: string;
    begin

    RegQueryStringValue(HKLM, 'HKEY_LOCAL_MACHINE\SOFTWARE\Classes\IconExtractor\DefaultIcon', '', InstallPath)

    Result := InstallPath;
    end;

结果如下:

  

结果= C:\ ProgramFiles \ Solutions \ Extractor \ tools \ v3 \ iconextractor.exe,1

但我只想删除最后3个路径元素

  

C:\ Program Files \ Solutions \ Extractor

我怎么做?

1 个答案:

答案 0 :(得分:1)

尝试一点代码

function GetDirName(const Value: string): string;
var 
 InstallPath : string;
 I,bscount   : Integer;

begin
 RegQueryStringValue(HKLM,'HKEY_LOCAL_MACHINE\SOFTWARE\Classes\IconExtractor\DefaultIcon',
                        '', InstallPath);
 bscount := 0;

 for I := Length(InstallPath) downto 1 do begin
   if InstallPath[I] = '\' then Inc(bscount);
   if bscount = 3 then begin
      InstallPath := Copy(InstallPath,1,I-1);
      break;
   end;
end;// for

Result := InstallPath;
end;