Method

GioFileEnumeratoriterate

since: 2.44

Declaration [src]

gboolean
g_file_enumerator_iterate (
  GFileEnumerator* direnum,
  GFileInfo** out_info,
  GFile** out_child,
  GCancellable* cancellable,
  GError** error
)

Description [src]

A version of g_file_enumerator_next_file() that’s easier to use correctly from C programs.

With g_file_enumerator_next_file(), the boolean return value signifies “end of iteration or error”, which requires allocation of a temporary GError to distinguish which one.

In contrast, with this function, a false return from g_file_enumerator_iterate() always means “error”. End of iteration is signaled by out_info or out_child being NULL.

Another crucial difference is that the references for out_info and out_child are owned by direnum (they are cached as hidden properties). You must not unref them in your own code. This makes memory management significantly easier for C code in combination with loops.

Finally, this function optionally allows retrieving a corresponding GFile as well as each GFileInfo.

To use this, G_FILE_ATTRIBUTE_STANDARD_NAME must have been listed in the attributes list used when creating the GFileEnumerator.

You must specify at least one of out_info or out_child.

The code pattern for correctly using g_file_enumerator_iterate() from C is:

direnum = g_file_enumerate_children (file, ...);
while (TRUE)
  {
    GFileInfo *info = NULL;

    if (!g_file_enumerator_iterate (direnum, &info, NULL, cancellable, error))
      goto out;

    if (info == NULL)
      break;

    // do stuff with "info"; do not unref it! ...
  }

out:
  g_object_unref (direnum); // Note: frees the last @info

Available since: 2.44

Parameters

out_info

Type: GFileInfo

Return location for the next file info object, or NULL.

The argument will be set by the function.
The argument can be NULL.
The returned data is owned by the instance.
out_child

Type: GFile

Return location for the next file object, or NULL.

The argument will be set by the function.
The argument can be NULL.
The returned data is owned by the instance.
cancellable

Type: GCancellable

Optional cancellable object.

The argument can be NULL.
The data is owned by the caller of the method.
error

Type: GError **

The return location for a recoverable error.

The argument can be NULL.
If the return location is not NULL, then you must initialize it to a NULL GError*.
The argument will be left initialized to NULL by the method if there are no errors.
In case of error, the argument will be set to a newly allocated GError; the caller will take ownership of the data, and be responsible for freeing it.

Return value

Type: gboolean

True on success or “end of iteration”; false on error.