Recent

Author Topic: How to load files from application subdirectory?  (Read 1498 times)

stem

  • Jr. Member
  • **
  • Posts: 84
How to load files from application subdirectory?
« on: November 07, 2021, 01:54:05 pm »
Hi,

I have a Lazarus application that loads files that are stored in
the directory "extra" which is a subdirectory of the application directory.

This line works in Windows as well as in Linux:

Code: Pascal  [Select][+][-]
  1. dir := ExtractFileDir(Application.Exename) + DirectorySeparator + 'extra';

How can I adjust the code so that it also works with MacOS?

Thank you!  :)

stem

wp

  • Hero Member
  • *****
  • Posts: 9591
Re: How to load files from application subdirectory?
« Reply #1 on: November 07, 2021, 02:10:48 pm »
Code: Text  [Select][+][-]
  1. dir := Application.Location + 'extra';
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

winni

  • Hero Member
  • *****
  • Posts: 3045
Re: How to load files from application subdirectory?
« Reply #2 on: November 07, 2021, 02:55:56 pm »
Hi

For all OS:

Code: Pascal  [Select][+][-]
  1. dir := Application.Location;
  2. if dir[length(dir)]  <> DirectorySeparator then dir := dir +  DirectorySeparator;
  3. dir := dir +'extra';
  4.  

Winni

ezlage

  • New Member
  • *
  • Posts: 29
    • GitHub

 

TinyPortal © 2005-2018