Access files with URL in Resources folder

I used ProJucer to add some files to Resources, and marked them as XCODE resource…

What is the URL to use to access such files ?
juce::URL resource_file_URL("/Resource/Filename");

and it doesn’t work.

I 'm looking for a relative path to access the resources instead of an absolute path

juce::URL is intended for accessing webpages, I don’t know that it can be used to access local files.

If you want to load a file from disk, you should use juce::File:

const auto cwd = juce::File::getCurrentWorkingDirectory();
const auto resourceFile = cwd.getChildFile ("Resource/Filename");

Alternatively, if you don’t want to have to ship your resource files separately to your app, you can mark them as binary resources in the Projucer and access them through the auto-generated BinaryData namespace. For example, for an image:

const auto img = juce::ImageCache::getFromMemory (BinaryData::myImage_png,
                                                  BinaryData::myImage_pngSize);
1 Like

But don’t ever use getCurrentWorkingDirectory(). It is in 99% of the cases not what you expect in a non-console application. And especially not in a plugin.

To access the Resources in a bundle use currentExecutableFile:

auto bundle = juce::File::getSpecialLocation (juce::File::currentExecutableFile).getParentDirectory().getParentDirectory();
auto file = bundle.getChildFile ("Resources").getChildFile ("filename");

The URL class can access local files using file:// but why go the extra mile if you know it is a file. Plus it is really adviseable to use juce::File::getSpecialLocation() as start to build any path.