I have a Delphi application executing and when I call GetCurrentDir
the following returns:
C:\dev\w32\2015\BCSLBDemo\Win32\Debug
When I call ExtractFileDir(GetCurrentDir())
I receive the following:
C:\dev\w32\2015\BCSLBDemo\Win32
What I desire is C:\dev\w32\2015\BCSLBDemo
function RetRoot: string;
var
i: Integer;
buf: string;
begin
Result := '';
buf := ExtractFileDir(GetCurrentDir());
i := Length(buf);
repeat
dec(i);
until (buf[i] = '\') or (i < 3);
if buf[i] = '\' then
begin
Delete(buf, i, Length(buf));
Result := buf;
end;
end;
I wrote this function to get the desired result. I would like to know if there is a better approach to accomplish retrieving the root directory of a Delphi executable.
ExtractFileDir(ParamStr(0))
to get the directory containing the executable. And to step up two directoriesExtractFileDir(ExtractFileDir(ExtractFileDir(ParamStr(0))))
. But why would you want to step up two directories? That seems plain weird. If you want better help, then you should explain what you are going to do with this information. – GrotesqueryBCSLBDemo
is your project root, not your executable root. Your executable is running from theWin32\Debug
folder, because that is where the project is configured to output the executable that it creates. The executable has no concept of the project. So what are you really trying to accomplish by having the executable find the project root? What is it going to do with that path? – Reputable..\..
– Schram