I ran across this program while writing a graphical frontend to the GNU Coreutils shred
program. When a user drags in a file that has spaces in it, such as my private data.docx
the GTK+ DND service represents those spaces as %20
. Using that example i would get (for the filename) my%20private&20data.docx
. I need to convert those to space characters because I use the fopen
function from stdio.h
. fopen
refuses to open filenames like that because it does not recognize %20
as a representation for a space.
No, you do not replace %20
with spaces. You decode the URL into a filename, with
g_filename_from_uri
:
gchar *
g_filename_from_uri (const gchar *uri,
gchar **hostname,
GError **error);
and usage therefore
gchar *filename = g_filename_from_uri(uri, NULL, NULL);
at its simplest.