Klasse FileEnumerator

Alle implementierten Schnittstellen:
PointerInterface

public class FileEnumerator extends PropertyHolder
`GFileEnumerator` allows 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 a `GFileEnumerator` for 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
a `GFileEnumerator` is closed, no further actions may be performed
on it, and it should be freed with [method@GObject.Object.unref].

https://docs.gtk.org/gio/class.FileEnumerator.html

  • Konstruktordetails

  • Methodendetails

    • getClassHandler

      public static ClassHandler getClassHandler()
    • close

      public boolean close(@Nullable Cancellable cancellable) throws AllocationError
      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.
      Parameter:
      cancellable - optional #GCancellable object, %NULL to ignore.
      Gibt zurück:
      #TRUE on success or #FALSE on error.
      Löst aus:
      AllocationError
    • closeAsync

      public void closeAsync(int io_priority, @Nullable Cancellable cancellable, FileEnumerator.OnAsyncReadyCallback callback, @Nullable Pointer 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().
      Parameter:
      io_priority - the [I/O priority](iface.AsyncResult.html#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
    • closeFinish

      public boolean closeFinish(@Nonnull AsyncResult result) throws AllocationError
      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.
      Parameter:
      result - a #GAsyncResult.
      Gibt zurück:
      %TRUE if the close operation has finished successfully.
      Löst aus:
      AllocationError
    • getChild

      public File getChild(@Nonnull FileInfo info)
      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().

      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:
      <!-- language="C" -->
         gchar *name = g_file_info_get_name (info);
         GFile *child = g_file_get_child (g_file_enumerator_get_container (enumr),
                                          name);
       
      Parameter:
      info - a #GFileInfo gotten from g_file_enumerator_next_file() or the async equivalents.
      Gibt zurück:
      a #GFile for the #GFileInfo passed it.
    • getContainer

      public File getContainer()
      Get the #GFile container which is being enumerated.
      Gibt zurück:
      the #GFile which is being enumerated.
    • hasPending

      public boolean hasPending()
      Checks if the file enumerator has pending operations.
      Gibt zurück:
      %TRUE if the @enumerator has pending operations.
    • isClosed

      public boolean isClosed()
      Checks if the file enumerator has been closed.
      Gibt zurück:
      %TRUE if the @enumerator is closed.
    • nextFile

      public FileInfo nextFile(@Nullable Cancellable cancellable) throws AllocationError
      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 %NULL and sets @error to the error. If the
      enumerator is at the end, %NULL will be returned and @error will
      be unset.
      Parameter:
      cancellable - optional #GCancellable object, %NULL to ignore.
      Gibt zurück:
      A #GFileInfo or %NULL on error or end of enumerator. Free the returned object with g_object_unref() when no longer needed.
      Löst aus:
      AllocationError
    • nextFilesAsync

      public void nextFilesAsync(int num_files, int io_priority, @Nullable Cancellable cancellable, FileEnumerator.OnAsyncReadyCallback callback, @Nullable Pointer 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.

      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 g_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
      %G_IO_ERROR_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 %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.
      Parameter:
      num_files - the number of file info objects to request
      io_priority - the [I/O priority](iface.AsyncResult.html#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
    • nextFilesFinish

      public List nextFilesFinish(@Nonnull AsyncResult result) throws AllocationError
      Finishes the asynchronous operation started with g_file_enumerator_next_files_async().
      Parameter:
      result - a #GAsyncResult.
      Gibt zurück:
      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.
      Löst aus:
      AllocationError
    • setPending

      public void setPending(boolean pending)
      Sets the file enumerator as having pending operations.
      Parameter:
      pending - a boolean value.
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()