Gio.FileEnumerator¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
w/co |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
|---|---|---|---|
parent_instance |
r |
Class Details¶
- class Gio.FileEnumerator(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
GFileEnumeratorallows you to operate on a set of [iface`Gio`.File] objects, returning a [class`Gio`.FileInfo] structure for each file enumerated (e.g. [method`Gio`.File.enumerate_children] will return aGFileEnumeratorfor each of the children within a directory).To get the next file’s information from a
GFileEnumerator, use [method`Gio`.FileEnumerator.next_file] or its asynchronous version, [method`Gio`.FileEnumerator.next_files_async]. Note that the asynchronous version will return a list of [class`Gio`.FileInfo] 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 [method`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
GFileEnumerator, use [method`Gio`.FileEnumerator.close], or its asynchronous version, [method`Gio`.FileEnumerator.close_async]. Once aGFileEnumeratoris closed, no further actions may be performed on it, and it should be freed with [method`GObject`.Object.unref].- close(cancellable)[source]¶
- Parameters:
cancellable (
Gio.CancellableorNone) – optional cancellable object- Raises:
- Returns:
true on success; false otherwise
- Return type:
Releases all resources used by this enumerator.
The enumerator will return [error`Gio`.IOErrorEnum.CLOSED] on all subsequent 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 requestcancellable (
Gio.CancellableorNone) – optional cancellable objectcallback (
Gio.AsyncReadyCallbackorNone) – a callback to call when the request is satisfied
Asynchronously closes the file enumerator.
If cancellable is not
NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error [error`Gio`.IOErrorEnum.CANCELLED] will be returned by [method`Gio`.FileEnumerator.close_finish()].
- close_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult) – an async result- Raises:
- Returns:
true on success; false otherwise
- Return type:
Finishes closing a file enumerator, started by [method`Gio`.FileEnumerator.close_async].
If the file enumerator was already closed when [method`Gio`.FileEnumerator.close_async] was called, then this function will report [error`Gio`.IOErrorEnum.CLOSED] in error. If the file enumerator had a pending operation when the close operation was started, then [error`Gio`.IOErrorEnum.PENDING] will be reported. If the operation was cancelled from another thread using cancellable, [error`Gio`.IOErrorEnum.CANCELLED] will be reported.
- get_child(info)[source]¶
- Parameters:
info (
Gio.FileInfo) – a file info object received from [method`Gio`.FileEnumerator.next_file] or the async equivalent- Returns:
a file object for the file info object passed to it
- Return type:
Returns a new [iface`Gio`.File] 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 [method`Gio`.FileEnumerator.next_file].
To use this, [const`Gio`.FILE_ATTRIBUTE_STANDARD_NAME] must have been listed in the attributes list used when creating the [class`Gio`.FileEnumerator].
This is a convenience method that’s equivalent to: ``c char *name = g_file_info_get_name (info); GFile *child = g_file_get_child (g_file_enumerator_get_container (enumerator), name); ``
Added in version 2.36.
- get_container()[source]¶
- Returns:
the file which is being enumerated
- Return type:
Get the [iface`Gio`.File] container which is being enumerated.
Added in version 2.18.
- has_pending()[source]¶
- Returns:
true if the self has pending operations
- Return type:
Checks if the file enumerator has pending operations.
- is_closed()[source]¶
- Returns:
true if the self is closed
- Return type:
Checks if the file enumerator has been closed.
- iterate(cancellable)[source]¶
- Parameters:
cancellable (
Gio.CancellableorNone) – optional cancellable object- Raises:
- Returns:
true on success or “end of iteration”; false on error
- out_info:
return location for the next file info object, or
NULL- out_child:
return location for the next file object, or
NULL
- Return type:
(
bool, out_info:Gio.FileInfo, out_child:Gio.File)
A version of [method`Gio`.FileEnumerator.next_file] that’s easier to use correctly from C programs.
With [method`Gio`.FileEnumerator.next_file], the boolean return value signifies “end of iteration or error”, which requires allocation of a temporary [type`GLib`.Error] to distinguish which one.
In contrast, with this function, a false return from [method`Gio`.FileEnumerator.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 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 corresponding [iface`Gio`.File] as well as each [class`Gio`.FileInfo].
To use this, [const`Gio`.FILE_ATTRIBUTE_STANDARD_NAME] must have been listed in the attributes list used when creating the [class`Gio`.FileEnumerator].
You must specify at least one of out_info or out_child.
The code pattern for correctly using [method`Gio`.FileEnumerator.iterate] from C is:
```c direnum =
Gio.File.enumerate_children(file, …); while (True) {Gio.FileInfo*info =None;if (!:obj:Gio.FileEnumerator.iterate (direnum, &info,
None, cancellable, error)) goto out;if (info ==
None) break;// do stuff with “info”; do not unref it! … }
out:
GObject.Object.unref(direnum); // Note: frees the last info ```Added in version 2.44.
- next()¶
The type of the None singleton.
- next_file(cancellable)[source]¶
- Parameters:
cancellable (
Gio.CancellableorNone) – optional cancellable object- Raises:
- Returns:
A file info object, or
NULLon error or end of enumerator- Return type:
Gio.FileInfoorNone
Returns information for the next file in the enumerated object.
Will block until the information is available. The [class`Gio`.FileInfo] returned from this function will contain attributes that match the attribute string that was passed when the file enumerator was created.
See the documentation of [class`Gio`.FileEnumerator] for information about the order of returned files.
On error, returns
NULLand sets error to the error. If the enumerator is at the end,NULLwill 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 requestio_priority (
int) – the I/O priority of the requestcancellable (
Gio.CancellableorNone) – optional cancellable objectcallback (
Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
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 [class`Gio`.FileEnumerator] 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 [method`Gio`.FileEnumerator.next_files_async] will typically have returned fewer than num_files items.
If a request is cancelled the callback will be called with [error`Gio`.IOErrorEnum.CANCELLED].
This leads to the following pseudo-code usage: ```c g_autoptr(
Gio.File) dir = get_directory (); g_autoptr(Gio.FileEnumerator) enumerator =None; g_autolist(Gio.FileInfo) files =None; g_autoptr(GLib.Error) local_error =None;enumerator = yield
Gio.File.enumerate_children_async(dir,Gio.FILE_ATTRIBUTE_STANDARD_NAME“,”Gio.FILE_ATTRIBUTE_STANDARD_TYPE,Gio.FileQueryInfoFlags.NONE,GLib.PRIORITY_DEFAULT, cancellable, …, &local_error); if (enumerator ==None) 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
Gio.FileEnumerator.next_files_async(enumerator, 5, // number of files to requestGLib.PRIORITY_DEFAULT, cancellable, …, &local_error);// Process the returned files, but don’t assume that exactly 5 were returned. for (
GLib.List*l = files; l !=None; l = l->next) {Gio.FileInfo*info = l->data; handle_file_info (info); } } while (files !=None);if (local_error !=
None&& !:obj:GLib.Error.matches (local_error, G_IO_ERROR,Gio.IOErrorEnum.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 [error`Gio`.IOErrorEnum.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 [const`GLib`.PRIORITY_DEFAULT].
- next_files_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult) – an async result- Raises:
- Returns:
a list of file info objects
- Return type:
Finishes the asynchronous operation started with [method`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 requestcancellable (
Gio.CancellableorNone) – optional cancellable objectcallback (
Gio.AsyncReadyCallbackorNone) – a callback to call when the request is satisfied
Asynchronously closes the file enumerator.
If cancellable is not
NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error [error`Gio`.IOErrorEnum.CANCELLED] will be returned by [method`Gio`.FileEnumerator.close_finish()].
- do_close_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult) – an async result- Returns:
true on success; false otherwise
- Return type:
Finishes closing a file enumerator, started by [method`Gio`.FileEnumerator.close_async].
If the file enumerator was already closed when [method`Gio`.FileEnumerator.close_async] was called, then this function will report [error`Gio`.IOErrorEnum.CLOSED] in error. If the file enumerator had a pending operation when the close operation was started, then [error`Gio`.IOErrorEnum.PENDING] will be reported. If the operation was cancelled from another thread using cancellable, [error`Gio`.IOErrorEnum.CANCELLED] will be reported.
- do_close_fn(cancellable) virtual¶
- Parameters:
cancellable (
Gio.CancellableorNone)- Return type:
- do_next_file(cancellable) virtual¶
- Parameters:
cancellable (
Gio.CancellableorNone) – optional cancellable object- Returns:
A file info object, or
NULLon error or end of enumerator- Return type:
Gio.FileInfoorNone
Returns information for the next file in the enumerated object.
Will block until the information is available. The [class`Gio`.FileInfo] returned from this function will contain attributes that match the attribute string that was passed when the file enumerator was created.
See the documentation of [class`Gio`.FileEnumerator] for information about the order of returned files.
On error, returns
NULLand sets error to the error. If the enumerator is at the end,NULLwill 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 requestio_priority (
int) – the I/O priority of the requestcancellable (
Gio.CancellableorNone) – optional cancellable objectcallback (
Gio.AsyncReadyCallbackorNone) – callback to call when the request is satisfied
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 [class`Gio`.FileEnumerator] 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 [method`Gio`.FileEnumerator.next_files_async] will typically have returned fewer than num_files items.
If a request is cancelled the callback will be called with [error`Gio`.IOErrorEnum.CANCELLED].
This leads to the following pseudo-code usage: ```c g_autoptr(
Gio.File) dir = get_directory (); g_autoptr(Gio.FileEnumerator) enumerator =None; g_autolist(Gio.FileInfo) files =None; g_autoptr(GLib.Error) local_error =None;enumerator = yield
Gio.File.enumerate_children_async(dir,Gio.FILE_ATTRIBUTE_STANDARD_NAME“,”Gio.FILE_ATTRIBUTE_STANDARD_TYPE,Gio.FileQueryInfoFlags.NONE,GLib.PRIORITY_DEFAULT, cancellable, …, &local_error); if (enumerator ==None) 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
Gio.FileEnumerator.next_files_async(enumerator, 5, // number of files to requestGLib.PRIORITY_DEFAULT, cancellable, …, &local_error);// Process the returned files, but don’t assume that exactly 5 were returned. for (
GLib.List*l = files; l !=None; l = l->next) {Gio.FileInfo*info = l->data; handle_file_info (info); } } while (files !=None);if (local_error !=
None&& !:obj:GLib.Error.matches (local_error, G_IO_ERROR,Gio.IOErrorEnum.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 [error`Gio`.IOErrorEnum.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 [const`GLib`.PRIORITY_DEFAULT].
- do_next_files_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult) – an async result- Returns:
a list of file info objects
- Return type:
Finishes the asynchronous operation started with [method`Gio`.FileEnumerator.next_files_async()].
Property Details¶
- Gio.FileEnumerator.props.container¶
- Name:
container- Type:
- Default Value:
- Flags:
The container that is being enumerated.