Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

obtaining directory path

_yilmaz_yilmaz Posts: 150Member
hi;

I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.

Thanx...

Comments

  • SeriSeri Posts: 28Member
    : hi;
    :
    : I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.
    :
    : Thanx...
    :

    Do you mean the path for your application itself ?
    I don't have Delphi here but it's in the [b]Application[/b] component.
    Something like [b]Application.ExeName[/b] if I remember right. And to obtain the path respectively you can use [b]ExtractFilePath[/b] (not so sure about the name of the function either).
    Hope that helps.
  • zibadianzibadian Posts: 6,349Member
    : : hi;
    : :
    : : I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.
    : :
    : : Thanx...
    : :
    :
    : Do you mean the path for your application itself ?
    : I don't have Delphi here but it's in the [b]Application[/b] component.
    : Something like [b]Application.ExeName[/b] if I remember right. And to obtain the path respectively you can use [b]ExtractFilePath[/b] (not so sure about the name of the function either).
    : Hope that helps.
    :
    You can also use the GetParam() function for that. The zeroth param is the complete exe-name including the path. This can also be used in a console application without the 400 kB forms overhead.
  • _yilmaz_yilmaz Posts: 150Member
    Thanks to both. I need this to keep some additional text data related to the application.

    Is it good to keep such data in the same directory with the .exe file or is there any other way to do this?

    (I don't want to use an absolute path like "C:Program FilesMy Applicaton" because the user may want to install the application to some other location he/she wants)

    : : : hi;
    : : :
    : : : I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.
    : : :
    : : : Thanx...
    : : :
    : :
    : : Do you mean the path for your application itself ?
    : : I don't have Delphi here but it's in the [b]Application[/b] component.
    : : Something like [b]Application.ExeName[/b] if I remember right. And to obtain the path respectively you can use [b]ExtractFilePath[/b] (not so sure about the name of the function either).
    : : Hope that helps.
    : :
    : You can also use the GetParam() function for that. The zeroth param is the complete exe-name including the path. This can also be used in a console application without the 400 kB forms overhead.
    :

  • zibadianzibadian Posts: 6,349Member
    : Thanks to both. I need this to keep some additional text data related to the application.
    :
    : Is it good to keep such data in the same directory with the .exe file or is there any other way to do this?
    :
    : (I don't want to use an absolute path like "C:Program FilesMy Applicaton" because the user may want to install the application to some other location he/she wants)
    :
    : : : : hi;
    : : : :
    : : : : I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.
    : : : :
    : : : : Thanx...
    : : : :
    : : :
    : : : Do you mean the path for your application itself ?
    : : : I don't have Delphi here but it's in the [b]Application[/b] component.
    : : : Something like [b]Application.ExeName[/b] if I remember right. And to obtain the path respectively you can use [b]ExtractFilePath[/b] (not so sure about the name of the function either).
    : : : Hope that helps.
    : : :
    : : You can also use the GetParam() function for that. The zeroth param is the complete exe-name including the path. This can also be used in a console application without the 400 kB forms overhead.
    : :
    :
    :
    Getting the exe-path in run-time is the best way to ensure that that data file is in the same directory as the exe-file. It also makes the program easier to remove from the system. If you have a lot of data, you might also consider using a subdirectory in the exe-directory. Most games use this method. That is also very easy to implement once you have the exe-path.
  • ChessoChesso Posts: 17Member
    [b][red]This message was edited by Chesso at 2004-11-3 4:30:39[/red][/b][hr]
    Just a code example of how i usually do it.

    Procedure TForm1.Create(Sender: TObject);
    Var
    ExePath: String;
    Begin
    ExePath := ExtractFilePath(Application.ExeName);
    End;

    Just so you know this will give the path to the dir you exe resides in no / at the end like this c:myprogramsgame is how it would come out.

    Or of course global rather then redoing it all the time if you refer to it alot.
  • SeriSeri Posts: 28Member
    : Thanks to both. I need this to keep some additional text data related to the application.
    :
    : Is it good to keep such data in the same directory with the .exe file or is there any other way to do this?
    :
    : (I don't want to use an absolute path like "C:Program FilesMy Applicaton" because the user may want to install the application to some other location he/she wants)
    :
    You can use:
    [b]RootPath = ExtractFilePath(Application.ExeName)[/b]
    or
    [b]RootPath = ExtractFilePath(GetParam(0))[/b]
    Then you can have things like:
    [b]DataPath = RootPath + 'Data'[/b]
    Use it whenenver needed:
    [b]AssignFile(f, DataPath + 'config.sys')[/b]
    Hope this helps.
  • SeriSeri Posts: 28Member
    : : : hi;
    : : :
    : : : I want to obtain the exact directory which the executable itself resides in. I use the GetDir() procedure, but it returns the directory of the parameter file.
    : : :
    : : : Thanx...
    : : :
    : :
    : : Do you mean the path for your application itself ?
    : : I don't have Delphi here but it's in the [b]Application[/b] component.
    : : Something like [b]Application.ExeName[/b] if I remember right. And to obtain the path respectively you can use [b]ExtractFilePath[/b] (not so sure about the name of the function either).
    : : Hope that helps.
    : :
    : You can also use the GetParam() function for that. The zeroth param is the complete exe-name including the path. This can also be used in a console application without the 400 kB forms overhead.
    :
    That is a very good idea indeed.
Sign In or Register to comment.