Class: Gio::FileEnumerator

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#close(cancellable) ⇒ TrueClass

Releases all resources used by this enumerator, making the enumerator return %G_IO_ERROR_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.

Parameters:

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore.

Returns:

  • (TrueClass)

    #TRUE on success or #FALSE on error.

#close_async(io_priority, cancellable, callback, user_data) ⇒ nil

Asynchronously closes the file enumerator.

If cancellable is not nil, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be returned in g_file_enumerator_close_finish().

Parameters:

  • io_priority (Integer)

    the [I/O priority] of the request

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore.

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#close_finish(result) ⇒ TrueClass

Finishes closing a file enumerator, started from g_file_enumerator_close_async().

If the file enumerator was already closed when g_file_enumerator_close_async() was called, then this function will report %G_IO_ERROR_CLOSED in error, and return false. If the file enumerator had pending operation when the close operation was started, then this function will report %G_IO_ERROR_PENDING, and return false. If cancellable was not nil, then the operation may have been cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be set, and false will be returned.

Parameters:

Returns:

  • (TrueClass)

    true if the close operation has finished successfully.

#containerGio::File

Get the #GFile container which is being enumerated.

Returns:

  • (Gio::File)

    the #GFile which is being enumerated.

#container=(container) ⇒ Gio::File

Returns container.

Parameters:

Returns:

#get_child(info) ⇒ Gio::File

Return a new #GFile which refers to the file named by info in the source directory of enumerator. This function is primarily intended to be used inside loops with g_file_enumerator_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);

Parameters:

  • info (Gio::FileInfo)

    a GFile::Info gotten from g_file_enumerator_next_file() or the async equivalents.

Returns:

  • (Gio::File)

    a #GFile for the GFile::Info passed it.

#has_pendingTrueClass

Checks if the file enumerator has pending operations.

Returns:

  • (TrueClass)

    true if the enumerator has pending operations.

#is_closedTrueClass

Checks if the file enumerator has been closed.

Returns:

  • (TrueClass)

    true if the enumerator is closed.

#iterate(out_info, out_child, cancellable) ⇒ TrueClass

This is a version of g_file_enumerator_next_file() that’s easier to use correctly from C programs. With g_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 false return from g_file_enumerator_iterate() always means “error”. End of iteration is signaled by out_info or out_child being nil.

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 #GFile as well.

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;
  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 <b>info</b>

]|

Parameters:

  • out_info (Gio::FileInfo)

    Output location for the next GFile::Info, or nil

  • out_child (Gio::File)

    Output location for the next #GFile, or nil

  • cancellable (Gio::Cancellable)

    a #GCancellable

Returns:

  • (TrueClass)

#next_file(cancellable) ⇒ Gio::FileInfo

Returns information for the next file in the enumerated object. Will block until the information is available. The GFile::Info returned from this function will contain attributes that match the attribute string that was passed when the GFile::Enumerator was created.

See the documentation of GFile::Enumerator for information about the order of returned files.

On error, returns nil and sets error to the error. If the enumerator is at the end, nil will be returned and error will be unset.

Parameters:

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore.

Returns:

  • (Gio::FileInfo)

    A GFile::Info or nil on error or end of enumerator. Free the returned object with g_object_unref() when no longer needed.

#next_files_async(num_files, io_priority, cancellable, callback, user_data) ⇒ nil

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 GFile::Enumerator for 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 %G_IO_ERROR_CANCELLED.

During an async request no other sync and async calls are allowed, and will result in %G_IO_ERROR_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.

Parameters:

  • num_files (Integer)

    the number of file info objects to request

  • io_priority (Integer)

    the [I/O priority] of the request

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore.

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#next_files_finish(result) ⇒ GLib::List

Finishes the asynchronous operation started with g_file_enumerator_next_files_async().

Parameters:

Returns:

  • (GLib::List)

    a #GList of GFile::Infos. You must free the list with g_list_free() and unref the infos with g_object_unref() when you’re done with them.

#pending=(pending) ⇒ nil

Sets the file enumerator as having pending operations.

Parameters:

  • pending (TrueClass)

    a boolean value.

Returns:

  • (nil)