Recent

Author Topic: setting the working dir  (Read 9603 times)

Carver413

  • Full Member
  • ***
  • Posts: 119
setting the working dir
« on: February 09, 2011, 01:31:53 am »
I would like my program to use is current dir as a starting place for file operations but when I call GetCurrentDir I get the desktop as the current dir.
Is there a way to set it in lazarus ?

mas steindorff

  • Hero Member
  • *****
  • Posts: 603
Re: setting the working dir
« Reply #1 on: February 09, 2011, 01:48:50 am »
modify the desk top's shortcut "working directory" to be the same as your program :)
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

Carver413

  • Full Member
  • ***
  • Posts: 119
Re: setting the working dir
« Reply #2 on: February 09, 2011, 03:52:04 am »
this isn't exactly what I was looking for.In delphi it was possible to retrieve the programs directory from a function (don't remember what that was) but it did not require messing with a shortcut.

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: setting the working dir
« Reply #3 on: February 09, 2011, 04:48:44 am »

I think you are looking for this, ExtractFilePath(Application.ExeName);
Thanks.

Carver413

  • Full Member
  • ***
  • Posts: 119
Re: setting the working dir
« Reply #4 on: February 09, 2011, 04:56:37 am »
Thank you ;D

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12950
  • FPC developer.
Re: setting the working dir
« Reply #5 on: February 09, 2011, 04:28:16 pm »
Note that this functionality is not crossplatform.

(or even 100% compatible under windows, it doesn't work when your .exe is in zip folders, compressed with some forms of UPX, on some networkdrives etc)

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: setting the working dir
« Reply #6 on: February 09, 2011, 04:57:08 pm »
Yes, I can confirm that Application.Exename does NOT work after UPX compression on Linux.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

BioHazard

  • Jr. Member
  • **
  • Posts: 57
  • Starless...
Re: setting the working dir
« Reply #7 on: February 09, 2011, 09:34:55 pm »
This for functions from SysUtils unit might help you:

GetAppConfigDir
GetAppConfigFile
GetCurrentDir
GetUserDir

I use them four and they work on windows and linux.

They all are documented for example below just search function name in function reference:

http://lazarus-ccr.sourceforge.net/docs/rtl/sysutils/index-5.html

As in (still depending on your goal) modern application's data is stored per user - You can use GetAppConfigDir(False) - With False parameter it returns local config dir in users directory, with True global config dir and as in windows  'global config dir' is undefined thing - use it with False.

 

TinyPortal © 2005-2018