It derives from <GObject>.
<GFileEnumerator> allows you to operate on
a set of <GFile> objects, returning a
<GFileInfo> structure for each file enumerated
(e.g. file:enumerate-children
will return a <GFileEnumerator> for each of
the children within a directory).
To get the next file’s information from a
<GFileEnumerator>, use
file-enumerator:next-file or its
asynchronous version, file-enumerator:next-files-async. Note that the
asynchronous version will return a list of
<GFileInfo> objects, whereas the synchronous will
only return the next file in the enumerator.
The ordering of returned files is unspecified for non-Unix platforms;
for more information, see dir:read-name. On Unix, when operating on local
files, returned files will be sorted by inode number. Effectively you
can assume that the ordering of returned files will be stable between
successive calls (and applications) assuming the directory is unchanged.
If your application needs a specific ordering, such as by name or modification time, you will have to implement that in your application code.
To close a <GFileEnumerator>, use
file-enumerator:close?, or its
asynchronous version, file-enumerator:close-async. Once a
<GFileEnumerator> is closed, no further
actions may be performed on it, and it should be freed with
object:unref.
parent-instanceThe container that is being enumerated.
Its value is a <GFile>, or #f.
It can only be set when the object is made, with #:container. It
cannot be read.
Asynchronously closes the file enumerator.
If cancellable is not #f, then the operation can be
cancelled by triggering the cancellable object from another thread. If
the operation was cancelled, the error
cancelled will be returned in
file-enumerator:close-finish?.
Passed: a <GFileEnumerator>.
Passed: a 32-bit integer.
the I/O priority of the request
Passed, or left out: a <GCancellable>, or
#f.
optional <GCancellable> object, #f to
ignore.
Passed, or left out: a procedure, or #f.
a GAsyncReadyCallback to call when the
request is satisfied
See GAsyncReadyCallback for how it is
called.
Not passed: guile-gi supplies it.
the data to pass to callback function
Finishes closing a file enumerator, started from
file-enumerator:close-async.
If the file enumerator was already closed when file-enumerator:close-async was called, then this
function will report closed in error,
and return #f. If the file enumerator had pending operation when
the close operation was started, then this function will report
pending, and return #f. If
cancellable was not #f, then the operation may have been
cancelled by triggering the cancellable object from another thread. If
the operation was cancelled, the error
cancelled will be set, and #f will be
returned.
Passed: a <GFileEnumerator>.
Passed: a <GAsyncResult>.
Returned: a boolean.
#t if the close operation has finished successfully.
Releases all resources used by this enumerator, making the enumerator
return closed on all calls.
This will be automatically called when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible.
Passed: a <GFileEnumerator>.
Passed, or left out: a <GCancellable>, or
#f.
optional <GCancellable> object, #f to
ignore.
Returned: a boolean.
TRUE on success or FALSE on error.
Return a new <GFile> which refers to the file named
by info in the source directory of self. This function is
primarily intended to be used inside loops with
file-enumerator:next-file.
To use this, G_FILE_ATTRIBUTE_STANDARD_NAME must have been listed
in the attributes list used when creating the
<GFileEnumerator>.
This is a convenience method that’s equivalent to:
gchar *name = g_file_info_get_name (info);
GFile *child = g_file_get_child (g_file_enumerator_get_container (enumr),
name);
Passed: a <GFileEnumerator>.
Passed: a <GFileInfo>.
a <GFileInfo> gotten from
file-enumerator:next-file or the
async equivalents.
Returned: a <GFile>.
a <GFile> for the <GFileInfo>
passed it.
Get the <GFile> container which is being enumerated.
Passed: a <GFileEnumerator>.
Returned: a <GFile>.
the <GFile> which is being enumerated.
Checks if the file enumerator has pending operations.
Passed: a <GFileEnumerator>.
Returned: a boolean.
#t if the self has pending operations.
Checks if the file enumerator has been closed.
Passed: a <GFileEnumerator>.
Returned: a boolean.
#t if the self is closed.
This is a version of file-enumerator:next-file that’s easier to use correctly
from C programs. With file-enumerator:next-file, the gboolean return value
signifies "end of iteration or error", which requires allocation of a
temporary <GError>.
In contrast, with this function, a #f return from
file-enumerator:iterate
always means "error". End of iteration is signaled by
out-info or out-child being #f.
Another crucial difference is that the references for out-info and out-child are owned by self (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
<GFile> as well.
You must specify at least one of out-info or out-child.
The code pattern for correctly using file-enumerator: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
Passed: a <GFileEnumerator>.
an open <GFileEnumerator>
Passed, or left out: a <GCancellable>, or
#f.
Returned: a boolean.
Returned: a <GFileInfo>.
Output location for the next <GFileInfo>, or
#f
Returned: a <GFile>.
Output location for the next <GFile>, or #f
Returns information for the next file in the enumerated object. Will
block until the information is available. The
<GFileInfo> returned from this function will
contain attributes that match the attribute string that was passed when
the <GFileEnumerator> was created.
See the documentation of <GFileEnumerator>
for information about the order of returned files.
On error, returns #f and sets error to the error. If the
enumerator is at the end, #f will be returned and error
will be unset.
Passed: a <GFileEnumerator>.
Passed, or left out: a <GCancellable>, or
#f.
optional <GCancellable> object, #f to
ignore.
Returned: a <GFileInfo>, or #f.
A <GFileInfo> or #f on error or end of
enumerator. Free the returned object with object:unref when no longer needed.
Request information for a number of files from the enumerator asynchronously. When all I/O for the operation is finished the callback will be called with the requested information.
See the documentation of <GFileEnumerator>
for information about the order of returned files.
Once the end of the enumerator is reached, or if an error occurs, the
callback will be called with an empty list. In this case, the
previous call to file-enumerator:next-files-async will typically have
returned fewer than num-files items.
If a request is cancelled the callback will be called with
cancelled.
This leads to the following pseudo-code usage:
g_autoptr(GFile) dir = get_directory ();
g_autoptr(GFileEnumerator) enumerator = NULL;
g_autolist(GFileInfo) files = NULL;
g_autoptr(GError) local_error = NULL;
enumerator = yield g_file_enumerate_children_async (dir,
G_FILE_ATTRIBUTE_STANDARD_NAME ","
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
cancellable,
…,
&local_error);
if (enumerator == NULL)
g_error ("Error enumerating: %s", local_error->message);
// Loop until no files are returned, either because the end of the enumerator
// has been reached, or an error was returned.
do
{
files = yield g_file_enumerator_next_files_async (enumerator,
5, // number of files to request
G_PRIORITY_DEFAULT,
cancellable,
…,
&local_error);
// Process the returned files, but don’t assume that exactly 5 were returned.
for (GList *l = files; l != NULL; l = l->next)
{
GFileInfo *info = l->data;
handle_file_info (info);
}
}
while (files != NULL);
if (local_error != NULL &&
!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_error ("Error while enumerating: %s", local_error->message);
During an async request no other sync and async calls are allowed, and
will result in pending errors.
Any outstanding I/O request with higher priority (lower numerical value)
will be executed before an outstanding request with lower priority.
Default priority is G_PRIORITY_DEFAULT.
Passed: a <GFileEnumerator>.
Passed: a 32-bit integer.
the number of file info objects to request
Passed: a 32-bit integer.
the I/O priority of the request
Passed, or left out: a <GCancellable>, or
#f.
optional <GCancellable> object, #f to
ignore.
Passed, or left out: a procedure, or #f.
a GAsyncReadyCallback to call when the
request is satisfied
See GAsyncReadyCallback for how it is
called.
Not passed: guile-gi supplies it.
the data to pass to callback function
Finishes the asynchronous operation started with
file-enumerator:next-files-async.
Passed: a <GFileEnumerator>.
Passed: a <GAsyncResult>.
Returned: a list, each a <GFileInfo>.
a GList of GFileInfos. You must free the list with
g_list_free() and unref the infos with object:unref when you’re done with them.
Sets the file enumerator as having pending operations.
Passed: a <GFileEnumerator>.
Passed: a boolean.
a boolean value.
Asynchronously closes the file enumerator.
If cancellable is not #f, then the operation can be
cancelled by triggering the cancellable object from another thread. If
the operation was cancelled, the error
cancelled will be returned in
file-enumerator:close-finish?.
To override it in a new class, give register-type #:vfuncs
`((close-async . ,procedure)). The procedure is called as
(procedure self io-priority cancellable callback user-data).
Passed: the class whose implementation to call:
<GFileEnumerator>, or a class that derives
from it, or its GType number.
Passed: a <GFileEnumerator>.
Passed: a 32-bit integer.
the I/O priority of the request
Passed, or left out: a <GCancellable>, or
#f.
optional <GCancellable> object, #f to
ignore.
Passed, or left out: a procedure, or #f.
a GAsyncReadyCallback to call when the
request is satisfied
See GAsyncReadyCallback for how it is
called.
Not passed: guile-gi supplies it.
the data to pass to callback function
Finishes closing a file enumerator, started from
file-enumerator:close-async.
If the file enumerator was already closed when file-enumerator:close-async was called, then this
function will report closed in error,
and return #f. If the file enumerator had pending operation when
the close operation was started, then this function will report
pending, and return #f. If
cancellable was not #f, then the operation may have been
cancelled by triggering the cancellable object from another thread. If
the operation was cancelled, the error
cancelled will be set, and #f will be
returned.
To override it in a new class, give register-type #:vfuncs
`((close-finish . ,procedure)). The procedure is called as
(procedure self result) ⇒ %return.
Passed: the class whose implementation to call:
<GFileEnumerator>, or a class that derives
from it, or its GType number.
Passed: a <GFileEnumerator>.
Passed: a <GAsyncResult>.
Returned: a boolean.
#t if the close operation has finished successfully.
To override it in a new class, give register-type #:vfuncs
`((close-fn . ,procedure)). The procedure is called as
(procedure self cancellable) ⇒ %return.
Passed: the class whose implementation to call:
<GFileEnumerator>, or a class that derives
from it, or its GType number.
Passed: a <GFileEnumerator>.
Passed, or left out: a <GCancellable>, or
#f.
Returned: a boolean.
Returns information for the next file in the enumerated object. Will
block until the information is available. The
<GFileInfo> returned from this function will
contain attributes that match the attribute string that was passed when
the <GFileEnumerator> was created.
See the documentation of <GFileEnumerator>
for information about the order of returned files.
On error, returns #f and sets error to the error. If the
enumerator is at the end, #f will be returned and error
will be unset.
To override it in a new class, give register-type #:vfuncs
`((next-file . ,procedure)). The procedure is called as
(procedure self cancellable) ⇒ %return.
Passed: the class whose implementation to call:
<GFileEnumerator>, or a class that derives
from it, or its GType number.
Passed: a <GFileEnumerator>.
Passed, or left out: a <GCancellable>, or
#f.
optional <GCancellable> object, #f to
ignore.
Returned: a <GFileInfo>, or #f.
A <GFileInfo> or #f on error or end of
enumerator. Free the returned object with object:unref when no longer needed.
Request information for a number of files from the enumerator asynchronously. When all I/O for the operation is finished the callback will be called with the requested information.
See the documentation of <GFileEnumerator>
for information about the order of returned files.
Once the end of the enumerator is reached, or if an error occurs, the
callback will be called with an empty list. In this case, the
previous call to file-enumerator:next-files-async will typically have
returned fewer than num-files items.
If a request is cancelled the callback will be called with
cancelled.
This leads to the following pseudo-code usage:
g_autoptr(GFile) dir = get_directory ();
g_autoptr(GFileEnumerator) enumerator = NULL;
g_autolist(GFileInfo) files = NULL;
g_autoptr(GError) local_error = NULL;
enumerator = yield g_file_enumerate_children_async (dir,
G_FILE_ATTRIBUTE_STANDARD_NAME ","
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NONE,
G_PRIORITY_DEFAULT,
cancellable,
…,
&local_error);
if (enumerator == NULL)
g_error ("Error enumerating: %s", local_error->message);
// Loop until no files are returned, either because the end of the enumerator
// has been reached, or an error was returned.
do
{
files = yield g_file_enumerator_next_files_async (enumerator,
5, // number of files to request
G_PRIORITY_DEFAULT,
cancellable,
…,
&local_error);
// Process the returned files, but don’t assume that exactly 5 were returned.
for (GList *l = files; l != NULL; l = l->next)
{
GFileInfo *info = l->data;
handle_file_info (info);
}
}
while (files != NULL);
if (local_error != NULL &&
!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_error ("Error while enumerating: %s", local_error->message);
During an async request no other sync and async calls are allowed, and
will result in pending errors.
Any outstanding I/O request with higher priority (lower numerical value)
will be executed before an outstanding request with lower priority.
Default priority is G_PRIORITY_DEFAULT.
To override it in a new class, give register-type #:vfuncs
`((next-files-async . ,procedure)). The procedure is called as
(procedure self num-files io-priority cancellable callback
user-data).
Passed: the class whose implementation to call:
<GFileEnumerator>, or a class that derives
from it, or its GType number.
Passed: a <GFileEnumerator>.
Passed: a 32-bit integer.
the number of file info objects to request
Passed: a 32-bit integer.
the I/O priority of the request
Passed, or left out: a <GCancellable>, or
#f.
optional <GCancellable> object, #f to
ignore.
Passed, or left out: a procedure, or #f.
a GAsyncReadyCallback to call when the
request is satisfied
See GAsyncReadyCallback for how it is
called.
Not passed: guile-gi supplies it.
the data to pass to callback function
Finishes the asynchronous operation started with
file-enumerator:next-files-async.
To override it in a new class, give register-type #:vfuncs
`((next-files-finish . ,procedure)). The procedure is called as
(procedure self result) ⇒ %return.
Passed: the class whose implementation to call:
<GFileEnumerator>, or a class that derives
from it, or its GType number.
Passed: a <GFileEnumerator>.
Passed: a <GAsyncResult>.
Returned: a list, each a <GFileInfo>.
a GList of GFileInfos. You must free the list with
g_list_free() and unref the infos with object:unref when you’re done with them.