Gio.FileEnumerator¶
| Subclasses: | None |
|---|
Methods¶
| Inherited: | GObject.Object (37) |
|---|---|
| Structs: | GObject.ObjectClass (5) |
close (cancellable) |
|
close_async (io_priority, cancellable, callback, *user_data) |
|
close_finish (result) |
|
get_child (info) |
|
get_container () |
|
has_pending () |
|
is_closed () |
|
iterate (cancellable) |
|
next () |
|
next_file (cancellable) |
|
next_files_async (num_files, io_priority, cancellable, callback, *user_data) |
|
next_files_finish (result) |
|
set_pending (pending) |
Virtual Methods¶
| Inherited: | GObject.Object (7) |
|---|
do_close_async (io_priority, cancellable, callback, *user_data) |
|
do_close_finish (result) |
|
do_close_fn (cancellable) |
|
do_next_file (cancellable) |
|
do_next_files_async (num_files, io_priority, cancellable, callback, *user_data) |
|
do_next_files_finish (result) |
Properties¶
| Name | Type | Flags | Short Description |
|---|---|---|---|
container |
Gio.File |
w/co | The container that is being enumerated |
Signals¶
| Inherited: | GObject.Object (1) |
|---|
Class Details¶
-
class
Gio.FileEnumerator(**kwargs)¶ Bases: GObject.ObjectAbstract: No Structure: Gio.FileEnumeratorClassGio.FileEnumeratorallows you to operate on a set ofGio.Files, returning aGio.FileInfostructure for each file enumerated (e.g.Gio.File.enumerate_children() will return aGio.FileEnumeratorfor each of the children within a directory).To get the next file’s information from a
Gio.FileEnumerator, useGio.FileEnumerator.next_file() or its asynchronous version,Gio.FileEnumerator.next_files_async(). Note that the asynchronous version will return a list ofGio.FileInfos, 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
GLib.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
Gio.FileEnumerator, useGio.FileEnumerator.close(), or its asynchronous version,Gio.FileEnumerator.close_async(). Once aGio.FileEnumeratoris closed, no further actions may be performed on it, and it should be freed withGObject.Object.unref().-
close(cancellable)[source]¶ Parameters: cancellable ( Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.Raises: GLib.ErrorReturns: Trueon success orFalseon error.Return type: boolReleases all resources used by this enumerator, making the enumerator return
Gio.IOErrorEnum.CLOSEDon 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.
-
close_async(io_priority, cancellable, callback, *user_data)[source]¶ Parameters: - io_priority (
int) – the I/O priority of the request - cancellable (
Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore. - callback (
Gio.AsyncReadyCallbackorNone) – aGio.AsyncReadyCallbackto call when the request is satisfied - user_data (
objectorNone) – the data to pass to callback function
Asynchronously closes the file enumerator.
If cancellable is not
None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLEDwill be returned inGio.FileEnumerator.close_finish().- io_priority (
-
close_finish(result)[source]¶ Parameters: result ( Gio.AsyncResult) – aGio.AsyncResult.Raises: GLib.ErrorReturns: Trueif the close operation has finished successfully.Return type: boolFinishes closing a file enumerator, started from
Gio.FileEnumerator.close_async().If the file enumerator was already closed when
Gio.FileEnumerator.close_async() was called, then this function will reportGio.IOErrorEnum.CLOSEDin error, and returnFalse. If the file enumerator had pending operation when the close operation was started, then this function will reportGio.IOErrorEnum.PENDING, and returnFalse. If cancellable was notNone, then the operation may have been cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLEDwill be set, andFalsewill be returned.
-
get_child(info)[source]¶ Parameters: info ( Gio.FileInfo) – aGio.FileInfogotten fromGio.FileEnumerator.next_file() or the async equivalents.Returns: a Gio.Filefor theGio.FileInfopassed it.Return type: Gio.FileReturn a new
Gio.Filewhich refers to the file named by info in the source directory of self. This function is primarily intended to be used inside loops withGio.FileEnumerator.next_file().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);
New in version 2.36.
-
get_container()[source]¶ Returns: the Gio.Filewhich is being enumerated.Return type: Gio.FileGet the
Gio.Filecontainer which is being enumerated.New in version 2.18.
-
has_pending()[source]¶ Returns: Trueif the self has pending operations.Return type: boolChecks if the file enumerator has pending operations.
-
is_closed()[source]¶ Returns: Trueif the self is closed.Return type: boolChecks if the file enumerator has been closed.
-
iterate(cancellable)[source]¶ Parameters: cancellable ( Gio.CancellableorNone) – aGio.CancellableRaises: GLib.ErrorReturns: out_info: Output location for the next Gio.FileInfo, orNoneout_child: Output location for the next Gio.File, orNoneReturn type: ( bool, out_info:Gio.FileInfo, out_child:Gio.File)This is a version of
Gio.FileEnumerator.next_file() that’s easier to use correctly from C programs. WithGio.FileEnumerator.next_file(), theboolreturn value signifies “end of iteration or error”, which requires allocation of a temporaryGLib.Error.In contrast, with this function, a
Falsereturn fromGio.FileEnumerator.iterate() *always* means “error”. End of iteration is signaled by out_info or out_child beingNone.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
Gio.Fileas well.You must specify at least one of out_info or out_child.
The code pattern for correctly using
Gio.FileEnumerator.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 @infoNew in version 2.44.
-
next()¶
-
next_file(cancellable)[source]¶ Parameters: cancellable ( Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.Raises: GLib.ErrorReturns: A Gio.FileInfoorNoneon error or end of enumerator. Free the returned object withGObject.Object.unref() when no longer needed.Return type: Gio.FileInfoorNoneReturns information for the next file in the enumerated object. Will block until the information is available. The
Gio.FileInforeturned from this function will contain attributes that match the attribute string that was passed when theGio.FileEnumeratorwas created.See the documentation of
Gio.FileEnumeratorfor information about the order of returned files.On error, returns
Noneand sets error to the error. If the enumerator is at the end,Nonewill be returned and error will be unset.
-
next_files_async(num_files, io_priority, cancellable, callback, *user_data)[source]¶ Parameters: - num_files (
int) – the number of file info objects to request - io_priority (
int) – the I/O priority of the request - cancellable (
Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore. - callback (
Gio.AsyncReadyCallbackorNone) – aGio.AsyncReadyCallbackto call when the request is satisfied - user_data (
objectorNone) – the data to pass to callback function
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
Gio.FileEnumeratorfor information about the order of returned files.The callback can be called with less than num_files files in case of error or at the end of the enumerator. In case of a partial error the callback will be called with any succeeding items and no error, and on the next request the error will be reported. If a request is cancelled the callback will be called with
Gio.IOErrorEnum.CANCELLED.During an async request no other sync and async calls are allowed, and will result in
Gio.IOErrorEnum.PENDINGerrors.Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is
GLib.PRIORITY_DEFAULT.- num_files (
-
next_files_finish(result)[source]¶ Parameters: result ( Gio.AsyncResult) – aGio.AsyncResult.Raises: GLib.ErrorReturns: a GLib.ListofGio.FileInfos. You must free the list with g_list_free() and unref the infos withGObject.Object.unref() when you’re done with them.Return type: [ Gio.FileInfo]Finishes the asynchronous operation started with
Gio.FileEnumerator.next_files_async().
-
set_pending(pending)[source]¶ Parameters: pending ( bool) – a boolean value.Sets the file enumerator as having pending operations.
-
do_close_async(io_priority, cancellable, callback, *user_data) virtual¶ Parameters: - io_priority (
int) – the I/O priority of the request - cancellable (
Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore. - callback (
Gio.AsyncReadyCallbackorNone) – aGio.AsyncReadyCallbackto call when the request is satisfied - user_data (
objectorNone) – the data to pass to callback function
Asynchronously closes the file enumerator.
If cancellable is not
None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLEDwill be returned inGio.FileEnumerator.close_finish().- io_priority (
-
do_close_finish(result) virtual¶ Parameters: result ( Gio.AsyncResult) – aGio.AsyncResult.Returns: Trueif the close operation has finished successfully.Return type: boolFinishes closing a file enumerator, started from
Gio.FileEnumerator.close_async().If the file enumerator was already closed when
Gio.FileEnumerator.close_async() was called, then this function will reportGio.IOErrorEnum.CLOSEDin error, and returnFalse. If the file enumerator had pending operation when the close operation was started, then this function will reportGio.IOErrorEnum.PENDING, and returnFalse. If cancellable was notNone, then the operation may have been cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLEDwill be set, andFalsewill be returned.
-
do_close_fn(cancellable) virtual¶ Parameters: cancellable ( Gio.CancellableorNone) –Return type: bool
-
do_next_file(cancellable) virtual¶ Parameters: cancellable ( Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore.Returns: A Gio.FileInfoorNoneon error or end of enumerator. Free the returned object withGObject.Object.unref() when no longer needed.Return type: Gio.FileInfoorNoneReturns information for the next file in the enumerated object. Will block until the information is available. The
Gio.FileInforeturned from this function will contain attributes that match the attribute string that was passed when theGio.FileEnumeratorwas created.See the documentation of
Gio.FileEnumeratorfor information about the order of returned files.On error, returns
Noneand sets error to the error. If the enumerator is at the end,Nonewill be returned and error will be unset.
-
do_next_files_async(num_files, io_priority, cancellable, callback, *user_data) virtual¶ Parameters: - num_files (
int) – the number of file info objects to request - io_priority (
int) – the I/O priority of the request - cancellable (
Gio.CancellableorNone) – optionalGio.Cancellableobject,Noneto ignore. - callback (
Gio.AsyncReadyCallbackorNone) – aGio.AsyncReadyCallbackto call when the request is satisfied - user_data (
objectorNone) – the data to pass to callback function
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
Gio.FileEnumeratorfor information about the order of returned files.The callback can be called with less than num_files files in case of error or at the end of the enumerator. In case of a partial error the callback will be called with any succeeding items and no error, and on the next request the error will be reported. If a request is cancelled the callback will be called with
Gio.IOErrorEnum.CANCELLED.During an async request no other sync and async calls are allowed, and will result in
Gio.IOErrorEnum.PENDINGerrors.Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is
GLib.PRIORITY_DEFAULT.- num_files (
-
do_next_files_finish(result) virtual¶ Parameters: result ( Gio.AsyncResult) – aGio.AsyncResult.Returns: a GLib.ListofGio.FileInfos. You must free the list with g_list_free() and unref the infos withGObject.Object.unref() when you’re done with them.Return type: [ Gio.FileInfo]Finishes the asynchronous operation started with
Gio.FileEnumerator.next_files_async().
-