How to get absolute FS file path from FileInfo

Can’t find how to retrieve absolute file path in FS, but file name only with get_name and what the difference with get_display_name method?

GFileInfo is information about a GFile.

So, you should have the GFile (and hence GFile name / path) in the first place to get a GFileInfo of the file.

1 Like

If you use Gtk.DirectoryList, the provided Gio.FileInfos will have a special standard::file attribute that contains the Gio.File.

You can get it with: Gio.FileInfo.get_attribute_object (fileinfo, “standard::file”)
and then use get_path() on it.

The name is the raw basename in the filesystem’s encoding. Use it when you need to interact with the filesystem APIs.
The display_name is a conversion of name to UTF-8, suitable to be displayed in Gtk.

2 Likes

and for info, you can use gio info myfile.txt in the command-line to query the list of available FileInfo attributes of a file.

That will give a good overview of the data you might be interested in.

1 Like

that’s it - I have FileInfo only in the DirectoryList context, thank you much!

Just successfully extracted by this way:

column_view.connect_activate(move |this, i| {
    use gtk::prelude::{Cast, FileExt, ListModelExt};
    println!(
        "{:?}",
        this.model()
            .unwrap()
            .item(i)
            .unwrap()
            .downcast_ref::<gtk::gio::FileInfo>()
            .unwrap()
            .attribute_object("standard::file")
            .unwrap()
            .downcast_ref::<gtk::gio::File>()
            .unwrap()
            .path()
    );
});