How to access files in OF/addons folder?

Hi, I’m trying to use files in OF/addons folder from my app.

I tried the below code but it doesn’t work.

void ofApp::setup(){

    string path = "../../../../../../../addons/bikers.jpg";
    img.load(path);
}

Is there any way to find out the path to the addons folder so I can access files in the folder?

You might miss the name of the addon?
Such as addons/{nameOfAddon/..../img}/bikers.jpg

Btw it could be problematic to look for addon folder.
For example, if you want to send your app to your friend, you should have entire oF folder structure. Also the position of executable is not the same between osx and windows/linux. OSX you have executable inside of youApp.app/Contents/…
So your relative path won’t work if you change os.

1 Like

Thanks. Is it possible to get the absolute path of data folder?

If you use, and the bikers.jpg is inside data folder it will work if you move the app to another location or another computer.

img.load("bikers.jpg");

Dont know how can you get the absolute path, but as hrs said using an absolute path is not a good idea

img.load( ofToDataPath("bikers.jpg" ) );

would be a lot more portable, in my experience it’s not guaranteed it will work just by the name

1 Like

if you add an ADDON_DATA entry to your addon’s addon_config.mk those files will be copied to the project data folder which is much more reliable than trying to figure out where an addon is since it could be in a local folder or even not at all if the binary is run on a different machine

2 Likes

Thank you so much!