Inno Setup - Get a path to parent folder

2020-03-30 06:46发布

问题:

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.

回答1:

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.