how to get dirname of a GFile?

630 views Asked by At

When using GIO and GVFS, how do I best get the directory name of a GFile object? There is a get_basename() function but no get_dirname().

The function should work for remote URIs as well. Also, it should be available in Python.

2

There are 2 answers

0
Jelko On

Take a look at this: http://docs.python.org/library/os.path.html. There is a dirname function which might help. Dont know if it will work for remote URIs as well. Just try it out.

0
Gang Chen On

First get the GFile for the dir, then get the name of the dir:

GFile* dir = g_file_get_parent(gfile));
char* dir_name = g_file_get_parse_name(dir);