0
static void open_file_chooser_button(GtkWidget *widget, gpointer user_data)
{
    static gint count;
    gchar *folder_path;

    count += 1;
    folder_path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(widget));

    g_print("count : %i, path : %s\n", count, folder_path);
}

It's my callback function. And I use next code to call out it.

g_signal_connect(file_chooser_button, "file-set", G_CALLBACK(open_file_chooser_button), NULL);

I build and execute a program. Then I press 'file chooser button' and select file.

But first is failed.

count : 1, path : (NULL)

and try again.

count : 2, path : C:\msys32\home\ga\Project

gtk_file_chooser_get_current_folder() isn't returned current folder path. It's returned privious folder path.

I want current folder path. How to get current folder path?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Gakgu
  • 123
  • 4
  • 9
  • 1
    From the documentation: " Note that this is the folder that the file chooser is currently displaying (e.g. "/home/username/Documents"), which is not the same as the currently-selected folder if the chooser is in GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER mode (e.g. "/home/username/Documents/selected-folder/". To get the currently-selected folder in that mode, use gtk_file_chooser_get_uri() as the usual way to get the selection. " So get the selected file and use one of GLib's path manipulation functions to get the folder out. – andlabs Sep 04 '16 at 20:36
  • Thank. But my file chooser is GTK_FILE_CHOOSER_ACTION_OPEN mode. gtk_file_chooser_get_uri() is activated well. Temporarily, I will be trying to create uri2path function. – Gakgu Sep 04 '16 at 21:28

0 Answers0