I have a path to a directory saved as a string, and wanted to know how I can easily and robustly extract the parent directory from this string?
I tried to see if there is some method for this in FileUtil and SysUtils, but haven't found anything so far.
The simplest way is to find the last path delimiter character and trim the source string. BTW there are some alternative:
And output is:
So using this technique the proper way is
ExpandFileName(IncludeTrailingPathDelimiter(sBasePath) + '..')
PS: We are using only
sysutils
unit so it is pure FPC solution and it is not require any LCL libraries.