When I would have this directory path:
C:\Program Files (x86)\Embarcadero\
The function I'm looking for should return:
C:\Program Files (x86)\
I've tried this code but it works only for files, not for directories:
function GetParentDirectory(const Path: string): string;
begin
Result := ExpandFileName(Path);
end;
Does anyone know what should I use to return path to the parent folder of a certain directory ?
You can use a couple of ways:
From a folder name:
ExtractFilePath(ExcludeTrailingPathDelimiter('C:\Parent\Child\'));
From a file name:
ExtractFilePath(ExcludeTrailingPathDelimiter(ExtractFilePath('C:\Parent\Child\app.exe')));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With