Jump to content
Incus J

How to obtain a path to a folder inside the app bundle?

Recommended Posts

I’ve added a folder of sample images to an FMX application.  They appear listed in the Deployment manager.  When the app is deployed on macOS, these images are included inside the application bundle in Contents/Resources/Startup/

 

How can I obtain a normal directory path to this internal folder, for internal use by the application?

 

For example is there something like TPath.GetInternalResourcesFolder; ?

 

I’m looking for the path to the folder only, rather than a full path to one single image file, so my app can load up all sample images in that folder when it starts up, without me having to reference each image filename individually in code.

Share this post


Link to post

I've found a post from April 2019 by Dave Nottage that looks like it might be adapted to do the trick:

// Bit of a "hack" to get the exact paths of the pdf files deployed to /Contents/Resources/Startup
  LSourceName := TPath.GetDirectoryName(ParamStr(0));
  LSourceName := TPath.Combine(StringReplace(LSourceName, '/MacOS', '', []), 'Resources/Startup/' + AFileName);

...seems to work OK 🙂.  Would make a nice addition to the built in TPath class:

class function TPath.GetAppResourcesPath:string;
var
  appPath:string;
begin
  appPath:=TPath.GetDirectoryName(ParamStr(0));
  result:=TPath.Combine(StringReplace(appPath,'/MacOS','',[]),'Resources/Startup/');
end;

...though it would need adapting further to produce a sane result on all supported platforms.

Edited by Incus J
  • Like 1

Share this post


Link to post

In the deployment manager, if you put ".\assets\internal\" as the Remote Path, on start of your app it copies those files to a directory (if they dont already exist) that you can get with:

tpath.GetDocumentsPath

  • Thanks 1

Share this post


Link to post
On 12/19/2020 at 12:53 AM, Doug Rudd said:

In the deployment manager, if you put ".\assets\internal\" as the Remote Path, on start of your app it copies those files to a directory (if they dont already exist) that you can get with:

tpath.GetDocumentsPath

That's very useful - thank you!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×