Question

I am trying to get the name of a file when I select it using a file chooser.

I managed to do

    gchar *name = gtk_file_chooser_get_filename(open_dialog);   

but that will return /home/user/Desktop/test.file and not test.file which I want to.

Is there any method to get the name of the file and not the uri of it?

Was it helpful?

Solution

How do you open the file if you have no the whole "URI" (path) to it?? If you want only test.file you can extract it from the whole path. There's the POSIX function basename and glib has a function too: g_path_get_basename.

OTHER TIPS

I would suggest using GIO (http://developer.gnome.org/gio/stable/). Its GFile and GFileInfo structures can be used for exactly what you need (also, GIO has the advantage to provide you with a portable file handling API).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top