Method

GLibPathBufset_filename

since: 2.76

Declaration

gboolean
g_path_buf_set_filename (
  GPathBuf* buf,
  const char* file_name
)

Description

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);

Available since: 2.76

Parameters

file_name

Type: const char*

The file name in the path.

The data is owned by the caller of the function.
The value is a file system path, using the OS encoding.

Return value

Type: gboolean

TRUE if the file name was replaced, and FALSE otherwise.