Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a path to parent folder in Inno Setup

I need to get the parent folder of {app}. It's standard if the end user didn't change the default, but if he did, it becomes a little more problematic. Basically, I need a function, that will output everything till the last \ backslash (inclusive). Wanted to try Pos, but it only detects the first instance of the character.

like image 953
George Hovhannisian Avatar asked Oct 19 '25 14:10

George Hovhannisian


2 Answers

Use 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.


Examples:

  • 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/'

It does not matter, if bar is a file or a (sub)folder. The function operates on the string only. It does not check any physical files or folders anyhow. So it does not even matter if any part of the path (or even the drive) exists or not.

like image 94
Martin Prikryl Avatar answered Oct 22 '25 03:10

Martin Prikryl


I think you can get the parent by simply typing:..\{app}

like image 26
DevLukas Avatar answered Oct 22 '25 03:10

DevLukas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!