Open files in a folder in data

GTK4 / libadwata 1.7 / python.

Making an application that might have many configuration files. I want to load all of them, not just a select few.

These files will be in a folder under data/. So data/extensions/.

But I couldn’t find a way to load a folder (file). I tried looking at Gio and
GFile, but these don’t quite match what I want to do.

I think my issue lies in that: I don’t know what the path is. Where is it? From where should I load? I’m confused, since GNOME Builder seems to make a setup for flatpak paths, but I can’t find a tutorial about this.

Files in your data/ folder need to be installed via the folder’s meson.build.

You can use GLib.get_user_data_dir to get the user’s data directory.

If you have more details, maybe I can help you more.

1 Like

After some debugging on the matrix channels:

  1. First, the files that were in data/extensions/ should instead be in a data folder - so, not accessed directly through the project’s path.
  2. To do so, I added a line in the meson.build file under data/ - The path is relative to the meson file, and install_dir is required. - This will add the files in either .var/app/ or wherever your flatpaks are. Particularly, in the data folder.
install_subdir('extensions', install_dir: get_option('datadir'))
  1. Then, we can access it by getting the folder at /app/share/extensions/ with Gio
Gio.File.new_for_path("/app/share/collections")

And then, to get the files, it’s something to do with gio.enumerate_children.