在 Inno Setup 中获取父文件夹的路径

Get a path to parent folder in Inno Setup

我需要获取 {app} 的父文件夹。如果最终用户没有更改默认值,这是标准的,但如果他这样做了,问题就多了一点。基本上,我需要一个函数,它将输出所有内容直到最后一个 \ 反斜杠(包括)。想尝试 Pos,但它只检测到字符的第一个实例。

使用the ExtractFilePath function:

Extracts the drive and directory parts of the given file name. The resulting string is the leftmost characters of FileName, up to and including the colon or backslash that separates the path information from the name and extension. The resulting string is empty if FileName contains no drive and directory parts.


示例:

  • ExtractFilePath('C:\foo\bar') => 'C:\foo\'
  • ExtractFilePath('C:\foo\bar\') => 'C:\foo\bar\'
  • ExtractFilePath('C:\foo\foo\bar') => 'C:\foo\foo\'
  • ExtractFilePath('..\foo\foo\bar') => '..\foo\foo\'
  • ExtractFilePath('C:bar') => 'C:'
  • ExtractFilePath('\server\foo\bar') => '\server\foo\'
  • ExtractFilePath('foo') => ''
  • ExtractFilePath('\foo') => '\'
  • ExtractFilePath('') => ''
  • ExtractFilePath('C:/foo/bar') => 'C:/foo/'
  • ExtractFilePath('C:/foo/bar/') => 'C:/foo/bar/'

没关系,bar 是文件还是(子)文件夹。该函数仅对字符串进行操作。它不会检查任何物理文件或文件夹。因此,路径的任何部分(甚至驱动器)是否存在都没有关系。

我认为您只需输入以下内容即可获得父项:..\{app}