PathBuf

class PathBuf(pointer: <Error class: unknown class><<Error class: unknown class>>, cleaner: <Error class: unknown class>? = null) : ProxyInstance

GPathBuf is a helper type that allows you to easily build paths from individual elements, using the platform specific conventions for path separators.

g_auto (GPathBuf) path;

g_path_buf_init (&path);

g_path_buf_push (&path, "usr");
g_path_buf_push (&path, "bin");
g_path_buf_push (&path, "echo");

g_autofree char *echo = g_path_buf_to_path (&path);
g_assert_cmpstr (echo, ==, "/usr/bin/echo");

You can also load a full path and then operate on its components:

g_auto (GPathBuf) path;

g_path_buf_init_from_path (&path, "/usr/bin/echo");

g_path_buf_pop (&path);
g_path_buf_push (&path, "sh");

g_autofree char *sh = g_path_buf_to_path (&path);
g_assert_cmpstr (sh, ==, "/usr/bin/sh");

Since

2.76

Constructors

Link copied to clipboard
constructor()

Allocate a new PathBuf.

constructor(scope: <Error class: unknown class>)

Allocate a new PathBuf using the provided AutofreeScope.

constructor(pointer: <Error class: unknown class><<Error class: unknown class>>, cleaner: <Error class: unknown class>? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val glibPathBufPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
open override val handle: <Error class: unknown class>?

Functions

Link copied to clipboard
fun clear()

Clears the contents of the path buffer.

Link copied to clipboard

Clears the contents of the path buffer and returns the built path.

Link copied to clipboard
fun copy(): PathBuf

Copies the contents of a path buffer into a new GPathBuf.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Compare two proxy instances for equality. This will compare both the type of the instances, and their memory addresses.

Link copied to clipboard
fun free()

Frees a GPathBuf allocated by g_path_buf_new().

Link copied to clipboard

Frees a GPathBuf allocated by g_path_buf_new(), and returns the path inside the buffer.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun init(): PathBuf

Initializes a GPathBuf instance.

Link copied to clipboard
fun initFromPath(path: String? = null): PathBuf

Initializes a GPathBuf instance with the given path.

Link copied to clipboard
fun pop(): Boolean

Removes the last element of the path buffer.

Link copied to clipboard
fun push(path: String): PathBuf

Extends the given path buffer with @path.

Link copied to clipboard
fun setExtension(extension: String? = null): Boolean

Adds an extension to the file name in the path buffer.

Link copied to clipboard
fun setFilename(fileName: String): Boolean

Sets the file name of the path.

Link copied to clipboard
fun toPath(): String?

Retrieves the built path from the path buffer.