GLib.PathBuf¶
Fields¶
Name |
Type |
Access |
Description |
|---|---|---|---|
dummy |
[ |
r |
Methods¶
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- class GLib.PathBuf¶
GPathBufis a helper type that allows you to easily build paths from individual elements, using the platform specific conventions for path separators.```c g_auto (
GLib.PathBuf) path;GLib.PathBuf.init(&path);GLib.PathBuf.push(&path, “usr”);GLib.PathBuf.push(&path, “bin”);GLib.PathBuf.push(&path, “echo”);g_autofree
str*echo =GLib.PathBuf.to_path(&path); g_assert_cmpstr (echo, ==, “/usr/bin/echo”); ```You can also load a full path and then operate on its components:
```c g_auto (
GLib.PathBuf) path;GLib.PathBuf.init_from_path(&path, “/usr/bin/echo”);GLib.PathBuf.pop(&path);GLib.PathBuf.push(&path, “sh”);g_autofree
str*sh =GLib.PathBuf.to_path(&path); g_assert_cmpstr (sh, ==, “/usr/bin/sh”); ```New in version 2.76.
- classmethod equal(v1, v2)[source]¶
- Parameters:
- Returns:
TRUEif the two path buffers are equal, andFALSEotherwise- Return type:
Compares two path buffers for equality and returns
TRUEif they are equal.The path inside the paths buffers are not going to be normalized, so
X/Y/Z/A/..,X/./Y/ZandX/Y/Zare not going to be considered equal.This function can be passed to g_hash_table_new() as the
key_equal_funcparameter.New in version 2.76.
- clear()[source]¶
Clears the contents of the path buffer.
This function should be use to free the resources in a stack-allocated
GPathBufinitialized usingGLib.PathBuf.init() orGLib.PathBuf.init_from_path().New in version 2.76.
- clear_to_path()[source]¶
-
Clears the contents of the path buffer and returns the built path.
This function returns
NULLif theGPathBufis empty.See also:
GLib.PathBuf.to_path()New in version 2.76.
- free_to_path()[source]¶
-
Frees a
GPathBufallocated by g_path_buf_new(), and returns the path inside the buffer.This function returns
NULLif theGPathBufis empty.See also:
GLib.PathBuf.to_path()New in version 2.76.
- init()[source]¶
- Returns:
the initialized path builder
- Return type:
Initializes a
GPathBufinstance.New in version 2.76.
- init_from_path(path)[source]¶
- Parameters:
- Returns:
the initialized path builder
- Return type:
Initializes a
GPathBufinstance with the given path.New in version 2.76.
- pop()[source]¶
- Returns:
TRUEif the buffer was modified andFALSEotherwise- Return type:
Removes the last element of the path buffer.
If there is only one element in the path buffer (for example,
/on Unix-like operating systems or the drive on Windows systems), it will not be removed andFalsewill be returned instead.GPathBuf buf, cmp; g_path_buf_init_from_path (&buf, "/bin/sh"); g_path_buf_pop (&buf); g_path_buf_init_from_path (&cmp, "/bin"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_pop (&buf); g_path_buf_init_from_path (&cmp, "/"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_clear (&buf);
New in version 2.76.
- push(path)[source]¶
- Parameters:
path (
str) – a path- Returns:
the same pointer to self, for convenience
- Return type:
Extends the given path buffer with path.
If path is absolute, it replaces the current path.
If path contains a directory separator, the buffer is extended by as many elements the path provides.
On Windows, both forward slashes and backslashes are treated as directory separators. On other platforms,
GLib.DIR_SEPARATOR_Sis the only directory separator.GPathBuf buf, cmp; g_path_buf_init_from_path (&buf, "/tmp"); g_path_buf_push (&buf, ".X11-unix/X0"); g_path_buf_init_from_path (&cmp, "/tmp/.X11-unix/X0"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_push (&buf, "/etc/locale.conf"); g_path_buf_init_from_path (&cmp, "/etc/locale.conf"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_clear (&buf);
New in version 2.76.
- set_extension(extension)[source]¶
- Parameters:
- Returns:
TRUEif the extension was replaced, andFALSEotherwise- Return type:
Adds an extension to the file name in the path buffer.
If extension is
NULL, the extension will be unset.If the path buffer does not have a file name set, this function returns
FALSEand leaves the path buffer unmodified.New in version 2.76.
- set_filename(file_name)[source]¶
- Parameters:
file_name (
str) – the file name in the path- Returns:
TRUEif the file name was replaced, andFALSEotherwise- Return type:
Sets the file name of the path.
If the path buffer is empty, the filename is left unset and this function returns
FALSE.If the path buffer only contains the root element (on Unix-like operating systems) or the drive (on Windows), this is the equivalent of pushing the new file_name.
If the path buffer contains a path, this is the equivalent of popping the path buffer and pushing file_name, creating a sibling of the original path.
GPathBuf buf, cmp; g_path_buf_init_from_path (&buf, "/"); g_path_buf_set_filename (&buf, "bar"); g_path_buf_init_from_path (&cmp, "/bar"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_set_filename (&buf, "baz.txt"); g_path_buf_init_from_path (&cmp, "/baz.txt"); g_assert_true (g_path_buf_equal (&buf, &cmp); g_path_buf_clear (&cmp); g_path_buf_clear (&buf);
New in version 2.76.