## GFileEnumerator

GFileEnumerator — Enumerated Files Routines

## Synopsis

    #include <gio/gio.h>

                        GFileEnumerator;
    GFileInfo *         g_file_enumerator_next_file         (GFileEnumerator *enumerator,
                                                             GCancellable *cancellable,
                                                             GError **error);
    gboolean            g_file_enumerator_close             (GFileEnumerator *enumerator,
                                                             GCancellable *cancellable,
                                                             GError **error);
    void                g_file_enumerator_next_files_async  (GFileEnumerator *enumerator,
                                                             int num_files,
                                                             int io_priority,
                                                             GCancellable *cancellable,
                                                             GAsyncReadyCallback callback,
                                                             gpointer user_data);
    GList *             g_file_enumerator_next_files_finish (GFileEnumerator *enumerator,
                                                             GAsyncResult *result,
                                                             GError **error);
    void                g_file_enumerator_close_async       (GFileEnumerator *enumerator,
                                                             int io_priority,
                                                             GCancellable *cancellable,
                                                             GAsyncReadyCallback callback,
                                                             gpointer user_data);
    gboolean            g_file_enumerator_close_finish      (GFileEnumerator *enumerator,
                                                             GAsyncResult *result,
                                                             GError **error);
    gboolean            g_file_enumerator_is_closed         (GFileEnumerator *enumerator);
    gboolean            g_file_enumerator_has_pending       (GFileEnumerator *enumerator);
    void                g_file_enumerator_set_pending       (GFileEnumerator *enumerator,
                                                             gboolean pending);
    GFile *             g_file_enumerator_get_container     (GFileEnumerator *enumerator);

## Object Hierarchy

      GObject
       +----GFileEnumerator

## Properties

      "container"                GFile*                : Write / Construct Only

## Description

GFileEnumerator allows you to operate on a set of GFiles, returning a GFileInfo structure for each file enumerated (e.g. `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 `g_file_enumerator_next_file()` or its asynchronous version, `g_file_enumerator_next_files_async()`. Note that the asynchronous version will return a list of GFileInfos, whereas the synchronous will only return the next file in the enumerator.

To close a GFileEnumerator, use `g_file_enumerator_close()`, or its asynchronous version, `g_file_enumerator_close_async()`. Once a GFileEnumerator is closed, no further actions may be performed on it, and it should be freed with `g_object_unref()`.

## Details

### GFileEnumerator

    typedef struct _GFileEnumerator GFileEnumerator;

A per matched file iterator.

### g_file_enumerator_next_file ()

    GFileInfo *         g_file_enumerator_next_file         (GFileEnumerator *enumerator,
                                                             GCancellable *cancellable,
                                                             GError **error);

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.

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

`enumerator` : | a GFileEnumerator.
`cancellable` : | optional GCancellable object, `NULL` to ignore.
`error` : | location to store the error occuring, or `NULL` to ignore
Returns : | A GFileInfo or `NULL` on error or end of enumerator. Free the returned object with `g_object_unref()` when no longer needed.

### g_file_enumerator_close ()

    gboolean            g_file_enumerator_close             (GFileEnumerator *enumerator,
                                                             GCancellable *cancellable,
                                                             GError **error);

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.

`enumerator` : | a GFileEnumerator.
`cancellable` : | optional GCancellable object, `NULL` to ignore.
`error` : | location to store the error occuring, or `NULL` to ignore
Returns : | TRUE on success or FALSE on error.

### g_file_enumerator_next_files_async ()

    void                g_file_enumerator_next_files_async  (GFileEnumerator *enumerator,
                                                             int num_files,
                                                             int io_priority,
                                                             GCancellable *cancellable,
                                                             GAsyncReadyCallback callback,
                                                             gpointer user_data);

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.

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`.

`enumerator` : | a GFileEnumerator.
`num_files` : | the number of file info objects to request
`io_priority` : | the io priority of the request.
`cancellable` : | optional GCancellable object, `NULL` to ignore.
`callback` : | a GAsyncReadyCallback to call when the request is satisfied
`user_data` : | the data to pass to callback function

### g_file_enumerator_next_files_finish ()

    GList *             g_file_enumerator_next_files_finish (GFileEnumerator *enumerator,
                                                             GAsyncResult *result,
                                                             GError **error);

Finishes the asynchronous operation started with `g_file_enumerator_next_files_async()`.

`enumerator` : | a GFileEnumerator.
`result` : | a GAsyncResult.
`error` : | a GError location to store the error occuring, or `NULL` to ignore.
Returns : | a GList of GFileInfos. You must free the list with `g_list_free()` and unref the infos with `g_object_unref()` when you're done with them.

### g_file_enumerator_close_async ()

    void                g_file_enumerator_close_async       (GFileEnumerator *enumerator,
                                                             int io_priority,
                                                             GCancellable *cancellable,
                                                             GAsyncReadyCallback callback,
                                                             gpointer user_data);

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 `G_IO_ERROR_CANCELLED` will be returned in `g_file_enumerator_close_finish()`.

`enumerator` : | a GFileEnumerator.
`io_priority` : | the I/O priority of the request.
`cancellable` : | optional GCancellable object, `NULL` to ignore.
`callback` : | a GAsyncReadyCallback to call when the request is satisfied
`user_data` : | the data to pass to callback function

### g_file_enumerator_close_finish ()

    gboolean            g_file_enumerator_close_finish      (GFileEnumerator *enumerator,
                                                             GAsyncResult *result,
                                                             GError **error);

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 `NULL`, 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.

`enumerator` : | a GFileEnumerator.
`result` : | a GAsyncResult.
`error` : | a GError location to store the error occuring, or `NULL` to ignore.
Returns : | `TRUE` if the close operation has finished successfully.

### g_file_enumerator_is_closed ()

    gboolean            g_file_enumerator_is_closed         (GFileEnumerator *enumerator);

Checks if the file enumerator has been closed.

`enumerator` : | a GFileEnumerator.
Returns : | `TRUE` if the `enumerator` is closed.

### g_file_enumerator_has_pending ()

    gboolean            g_file_enumerator_has_pending       (GFileEnumerator *enumerator);

Checks if the file enumerator has pending operations.

`enumerator` : | a GFileEnumerator.
Returns : | `TRUE` if the `enumerator` has pending operations.

### g_file_enumerator_set_pending ()

    void                g_file_enumerator_set_pending       (GFileEnumerator *enumerator,
                                                             gboolean pending);

Sets the file enumerator as having pending operations.

`enumerator` : | a GFileEnumerator.
`pending` : | a boolean value.

### g_file_enumerator_get_container ()

    GFile *             g_file_enumerator_get_container     (GFileEnumerator *enumerator);

Get the GFile container which is being enumerated.

`enumerator` : | a GFileEnumerator
Returns : | the GFile which is being enumerated.

Since 2.18

## Property Details

### The `"container"` property

      "container"                GFile*                : Write / Construct Only

The container that is being enumerated.