iterate


Description:

[ Version ( since = "2.44" ) ]
public bool iterate (out unowned FileInfo out_info, out unowned File out_child, Cancellable? cancellable = null) throws Error

This is a version of next_file that's easier to use correctly from C programs.

With next_file, the gboolean return value signifies "end of iteration or error", which requires allocation of a temporary Error.

In contrast, with this function, a false return from 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 this (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 File as well.

You must specify at least one of out_info or out_child.

The code pattern for correctly using iterate from C is:

direnum = g_file_enumerate_children (file, ...);
while (TRUE)
{
GFileInfo *info;
if (!g_file_enumerator_iterate (direnum, &info, NULL, cancellable, error))
goto out;
if (!info)
break;
... do stuff with "info"; do not unref it! ...
}

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

Parameters:

this

an open FileEnumerator

out_info

Output location for the next FileInfo, or null

out_child

Output location for the next File, or null

cancellable

a Cancellable




2022 vala-language.org