Module: Gio::File

Defined in:
(unknown)

Overview

#GFile is a high level abstraction for manipulating files on a virtual file system. #GFiles are lightweight, immutable objects that do no I/O upon creation. It is necessary to understand that #GFile objects do not represent files, merely an identifier for a file. All file content I/O is implemented as streaming operations (see GInput::Stream and #GOutputStream).

To construct a #GFile, you can use:

  • g_file_new_for_path() if you have a path.

  • g_file_new_for_uri() if you have a URI.

  • g_file_new_for_commandline_arg() for a command line argument.

  • g_file_new_tmp() to create a temporary file from a template.

  • g_file_parse_name() from a UTF-8 string gotten from g_file_get_parse_name().

  • g_file_new_build_filename() to create a file from path elements.

One way to think of a #GFile is as an abstraction of a pathname. For normal files the system pathname is what is stored internally, but as #GFiles are extensible it could also be something else that corresponds to a pathname in a userspace implementation of a filesystem.

#GFiles make up hierarchies of directories and files that correspond to the files on a filesystem. You can move through the file system with #GFile using g_file_get_parent() to get an identifier for the parent directory, g_file_get_child() to get a child within a directory, g_file_resolve_relative_path() to resolve a relative path between two #GFiles. There can be multiple hierarchies, so you may not end up at the same root if you repeatedly call g_file_get_parent() on two different files.

All #GFiles have a basename (get with g_file_get_basename()). These names are byte strings that are used to identify the file on the filesystem (relative to its parent directory) and there is no guarantees that they have any particular charset encoding or even make any sense at all. If you want to use filenames in a user interface you should use the display name that you can get by requesting the %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info(). This is guaranteed to be in UTF-8 and can be used in a user interface. But always store the real basename or the #GFile to use to actually access the file, because there is no way to go from a display name to the actual name.

Using #GFile as an identifier has the same weaknesses as using a path in that there may be multiple aliases for the same file. For instance, hard or soft links may cause two different #GFiles to refer to the same file. Other possible causes for aliases are: case insensitive filesystems, short and long names on FAT/NTFS, or bind mounts in Linux. If you want to check if two #GFiles point to the same file you can query for the %G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial canonicalization of pathnames passed in, so that trivial differences in the path string used at creation (duplicated slashes, slash at end of path, “.” or “..” path segments, etc) does not create different #GFiles.

Many #GFile operations have both synchronous and asynchronous versions to suit your application. Asynchronous versions of synchronous functions simply have _async() appended to their function names. The asynchronous I/O functions call a GAsync::ReadyCallback which is then used to finalize the operation, producing a GAsyncResult which is then passed to the function’s matching _finish() operation.

It is highly recommended to use asynchronous calls when running within a shared main loop, such as in the main thread of an application. This avoids I/O operations blocking other sources on the main loop from being dispatched. Synchronous I/O operations should be performed from worker threads. See the

introduction to asynchronous programming section][async-programming

for

more.

Some #GFile operations almost always take a noticeable amount of time, and so do not have synchronous analogs. Notable cases include:

  • g_file_mount_mountable() to mount a mountable file.

  • g_file_unmount_mountable_with_operation() to unmount a mountable file.

  • g_file_eject_mountable_with_operation() to eject a mountable file.

## Entity Tags # #gfile-etag

One notable feature of #GFiles are entity tags, or “etags” for short. Entity tags are somewhat like a more abstract version of the traditional mtime, and can be used to quickly determine if the file has been modified from the version on the file system. See the HTTP 1.1 [specification](www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) for HTTP Etag headers, which are a very similar concept.

Instance Method Summary collapse

Instance Method Details

Returns:

  • (nil)

Returns:

  • (nil)

#_move_asyncnil

Returns:

  • (nil)

#_move_finishnil

Returns:

  • (nil)

#_query_settable_attributes_asyncnil

Returns:

  • (nil)

#_query_settable_attributes_finishnil

Returns:

  • (nil)

#_query_writable_namespaces_asyncnil

Returns:

  • (nil)

#_query_writable_namespaces_finishnil

Returns:

  • (nil)

#append_to(file, flags, cancellable) ⇒ Gio::FileOutputStream

Returns a GFile::OutputStream, or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileOutputStream)

    a GFile::OutputStream, or nil on error. Free the returned object with g_object_unref().

#append_to_async(file, flags, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • flags (Gio::FileCreateFlags)

    a set of GFile::CreateFlags

  • 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)

#append_to_finish(file, res) ⇒ Gio::FileOutputStream

Returns a valid GFile::OutputStream or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileOutputStream)

    a valid GFile::OutputStream or nil on error. Free the returned object with g_object_unref().

#basenameGio::filename

Gets the base name (the last component of the path) for a given #GFile.

If called for the top level of a system (such as the filesystem root or a uri like shost/) it will return a single directory separator (and on Windows, possibly a drive letter).

The base name is a byte string (not UTF-8). It has no defined encoding or rules other than it may not contain zero bytes. If you want to use filenames in a user interface you should use the display name that you can get by requesting the %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info().

This call does no blocking I/O.

Returns:

  • (Gio::filename)

    string containing the #GFile’s base name, or nil if given #GFile is invalid. The returned string should be freed with g_free() when no longer needed.

#copy(source, destination, flags, cancellable, progress_callback, progress_callback_data) ⇒ TrueClass

Returns true on success, false otherwise.

Parameters:

  • source (Gio::File)

    input #GFile

  • destination (Gio::File)

    destination #GFile

  • flags (Gio::FileCopyFlags)

    set of GFile::CopyFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • progress_callback (Gio::FileProgressCallback)

    function to callback with progress information, or nil if progress information is not needed

  • progress_callback_data (GObject)

    user data to pass to progress_callback

Returns:

  • (TrueClass)

    true on success, false otherwise.

#copy_async(source, destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, user_data) ⇒ nil

Parameters:

  • source (Gio::File)

    input #GFile

  • destination (Gio::File)

    destination #GFile

  • flags (Gio::FileCopyFlags)

    set of GFile::CopyFlags

  • io_priority (Integer)

    the [I/O priority] of the request

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • progress_callback (Gio::FileProgressCallback)

    function to callback with progress information, or nil if progress information is not needed

  • progress_callback_data (GObject)

    user data to pass to progress_callback

  • 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)

#copy_attributes(destination, flags, cancellable) ⇒ TrueClass

Copies the file attributes from source to destination.

Normally only a subset of the file attributes are copied, those that are copies in a normal file copy operation (which for instance does not include e.g. owner). However if #G_FILE_COPY_ALL_METADATA is specified in flags, then all the metadata that is possible to copy is copied. This is useful when implementing move by copy + delete source.

Parameters:

Returns:

  • (TrueClass)

    true if the attributes were copied successfully, false otherwise.

#copy_finish(file, res) ⇒ TrueClass

Returns a true on success, false on error.

Parameters:

Returns:

  • (TrueClass)

    a true on success, false on error.

#create(file, flags, cancellable) ⇒ Gio::FileOutputStream

Returns a GFile::OutputStream for the newly created file, or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileOutputStream)

    a GFile::OutputStream for the newly created file, or nil on error. Free the returned object with g_object_unref().

#create_async(file, flags, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • flags (Gio::FileCreateFlags)

    a set of GFile::CreateFlags

  • 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)

#create_finish(file, res) ⇒ Gio::FileOutputStream

Returns a GFile::OutputStream or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileOutputStream)

    a GFile::OutputStream or nil on error. Free the returned object with g_object_unref().

#create_readwrite(file, flags, cancellable) ⇒ Gio::FileIOStream

Returns a GFile::IOStream for the newly created file, or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileIOStream)

    a GFile::IOStream for the newly created file, or nil on error. Free the returned object with g_object_unref().

#create_readwrite_async(file, flags, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • flags (Gio::FileCreateFlags)

    a set of GFile::CreateFlags

  • 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)

#create_readwrite_finish(file, res) ⇒ Gio::FileIOStream

Returns a GFile::IOStream or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileIOStream)

    a GFile::IOStream or nil on error. Free the returned object with g_object_unref().

#delete(cancellable) ⇒ TrueClass

Deletes a file. If the file is a directory, it will only be deleted if it is empty. This has the same semantics as g_unlink().

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.

Parameters:

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if the file was deleted. false otherwise.

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

Asynchronously delete a file. If the file is a directory, it will only be deleted if it is empty. This has the same semantics as g_unlink().

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)

#delete_file(file, cancellable) ⇒ TrueClass

Returns true if the file was deleted. false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the file was deleted. false otherwise.

#delete_file_async(file, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • 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)

#delete_file_finish(file, result) ⇒ TrueClass

Returns true if the file was deleted. false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the file was deleted. false otherwise.

#delete_finish(result) ⇒ TrueClass

Finishes deleting a file started with g_file_delete_async().

Parameters:

Returns:

  • (TrueClass)

    true if the file was deleted. false otherwise.

#display_name_finish=(res) ⇒ Gio::File

Finishes setting a display name started with g_file_set_display_name_async().

Parameters:

Returns:

  • (Gio::File)

    a #GFile or nil on error. Free the returned object with g_object_unref().

#dup(file) ⇒ Gio::File

Returns a new #GFile that is a duplicate of the given #GFile.

Parameters:

Returns:

  • (Gio::File)

    a new #GFile that is a duplicate of the given #GFile.

#eject_mountable(file, flags, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • flags (Gio::MountUnmountFlags)

    flags affecting the operation

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied, or nil

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#eject_mountable_finish(file, result) ⇒ TrueClass

Returns true if the file was ejected successfully. false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the file was ejected successfully. false otherwise.

#eject_mountable_with_operation(file, flags, mount_operation, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • flags (Gio::MountUnmountFlags)

    flags affecting the operation

  • mount_operation (Gio::MountOperation)

    a GMount::Operation, or nil to avoid user interaction

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied, or nil

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#eject_mountable_with_operation_finish(file, result) ⇒ TrueClass

Returns true if the file was ejected successfully. false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the file was ejected successfully. false otherwise.

#enumerate_children(file, attributes, flags, cancellable) ⇒ Gio::FileEnumerator

Returns A GFile::Enumerator if successful, nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileEnumerator)

    A GFile::Enumerator if successful, nil on error. Free the returned object with g_object_unref().

#enumerate_children_async(file, attributes, flags, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • attributes (String)

    an attribute query string

  • flags (Gio::FileQueryInfoFlags)

    a set of GFile::QueryInfoFlags

  • 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)

#enumerate_children_finish(file, res) ⇒ Gio::FileEnumerator

Returns a GFile::Enumerator or nil if an error occurred. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileEnumerator)

    a GFile::Enumerator or nil if an error occurred. Free the returned object with g_object_unref().

#equal(file1, file2) ⇒ TrueClass

Returns true if file1 and file2 are equal.

Parameters:

Returns:

  • (TrueClass)

    true if file1 and file2 are equal.

#find_enclosing_mount(file, cancellable) ⇒ Gio::Mount

Returns a #GMount where the file is located or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::Mount)

    a #GMount where the file is located or nil on error. Free the returned object with g_object_unref().

#find_enclosing_mount_async(file, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    a #GFile

  • 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)

#find_enclosing_mount_finish(file, res) ⇒ Gio::Mount

Returns #GMount for given file or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::Mount)

    #GMount for given file or nil on error. Free the returned object with g_object_unref().

#get_basename(file) ⇒ String

Parameters:

Returns:

  • (String)

#get_child(name) ⇒ Gio::File

Gets a child of file with basename equal to name.

Note that the file with that specific name might not exist, but you can still have a #GFile that points to it. You can use this for instance to create that file.

This call does no blocking I/O.

Parameters:

  • name (Gio::filename)

    string containing the child’s basename

Returns:

  • (Gio::File)

    a #GFile to a child specified by name. Free the returned object with g_object_unref().

#get_child_for_display_name(file, display_name) ⇒ Gio::File

Returns a #GFile to the specified child, or nil if the display name couldn’t be converted. Free the returned object with g_object_unref().

Parameters:

  • file (Gio::File)

    input #GFile

  • display_name (String)

    string to a possible child

Returns:

  • (Gio::File)

    a #GFile to the specified child, or nil if the display name couldn’t be converted. Free the returned object with g_object_unref().

#get_parent(file) ⇒ Gio::File

Returns a #GFile structure to the parent of the given #GFile or nil if there is no parent. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::File)

    a #GFile structure to the parent of the given #GFile or nil if there is no parent. Free the returned object with g_object_unref().

#get_parse_name(file) ⇒ String

Returns a string containing the #GFile’s parse name. The returned string should be freed with g_free() when no longer needed.

Parameters:

Returns:

  • (String)

    a string containing the #GFile’s parse name. The returned string should be freed with g_free() when no longer needed.

#get_path(file) ⇒ String

Parameters:

Returns:

  • (String)

#get_relative_path(parent, descendant) ⇒ String

Parameters:

Returns:

  • (String)

#get_uri(file) ⇒ String

Returns a string containing the #GFile’s URI. The returned string should be freed with g_free() when no longer needed.

Parameters:

Returns:

  • (String)

    a string containing the #GFile’s URI. The returned string should be freed with g_free() when no longer needed.

#get_uri_scheme(file) ⇒ String

Returns a string containing the URI scheme for the given #GFile. The returned string should be freed with g_free() when no longer needed.

Parameters:

Returns:

  • (String)

    a string containing the URI scheme for the given #GFile. The returned string should be freed with g_free() when no longer needed.

#has_parent(parent) ⇒ TrueClass

Checks if file has a parent, and optionally, if it is parent.

If parent is nil then this function returns true if file has any parent at all. If parent is non-nil then true is only returned if file is an immediate child of parent.

Parameters:

  • parent (Gio::File)

    the parent to check for, or nil

Returns:

  • (TrueClass)

    true if file is an immediate child of parent (or any parent in the case that parent is nil).

#has_prefix(prefix) ⇒ TrueClass

Checks whether file has the prefix specified by prefix.

In other words, if the names of initial elements of file’s pathname match prefix. Only full pathname elements are matched, so a path like /foo is not considered a prefix of /foobar, only of /foo/bar.

A #GFile is not a prefix of itself. If you want to check for equality, use g_file_equal().

This call does no I/O, as it works purely on names. As such it can sometimes return false even if file is inside a prefix (from a filesystem point of view), because the prefix of file is an alias of prefix.

Parameters:

Returns:

  • (TrueClass)

    true if the file’s parent, grandparent, etc is prefix, false otherwise.

#has_uri_scheme(file, uri_scheme) ⇒ TrueClass

Returns true if #GFile’s backend supports the given URI scheme, false if URI scheme is nil, not supported, or #GFile is invalid.

Parameters:

  • file (Gio::File)

    input #GFile

  • uri_scheme (String)

    a string containing a URI scheme

Returns:

  • (TrueClass)

    true if #GFile’s backend supports the given URI scheme, false if URI scheme is nil, not supported, or #GFile is invalid.

#hash(file) ⇒ Integer

Returns 0 if file is not a valid #GFile, otherwise an integer that can be used as hash value for the #GFile. This function is intended for easily hashing a #GFile to add to a GHash::Table or similar data structure.

Parameters:

  • file (Gio::File)

    #gconstpointer to a #GFile

Returns:

  • (Integer)

    0 if file is not a valid #GFile, otherwise an integer that can be used as hash value for the #GFile. This function is intended for easily hashing a #GFile to add to a GHash::Table or similar data structure.

#is_native(file) ⇒ TrueClass

Returns true if file is native.

Parameters:

Returns:

  • (TrueClass)

    true if file is native

#load_bytes(cancellable, etag_out) ⇒ GLib::Bytes

Loads the contents of file and returns it as #GBytes.

If file is a resource:// based URI, the resulting bytes will reference the embedded resource instead of a copy. Otherwise, this is equivalent to calling g_file_load_contents() and g_bytes_new_take().

For resources, etag_out will be set to nil.

The data contained in the resulting #GBytes is always zero-terminated, but this is not included in the #GBytes length. The resulting #GBytes should be freed with g_bytes_unref() when no longer in use.

Parameters:

  • cancellable (Gio::Cancellable)

    a #GCancellable or nil

  • etag_out (String)

    a location to place the current entity tag for the file, or nil if the entity tag is not needed

Returns:

  • (GLib::Bytes)

    a #GBytes or nil and error is set

#load_bytes_async(cancellable, callback, user_data) ⇒ nil

Asynchronously loads the contents of file as #GBytes.

If file is a resource:// based URI, the resulting bytes will reference the embedded resource instead of a copy. Otherwise, this is equivalent to calling g_file_load_contents_async() and g_bytes_new_take().

callback should call g_file_load_bytes_finish() to get the result of this asynchronous operation.

See g_file_load_bytes() for more information.

Parameters:

  • cancellable (Gio::Cancellable)

    a #GCancellable or nil

  • 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)

#load_bytes_finish(result, etag_out) ⇒ GLib::Bytes

Completes an asynchronous request to g_file_load_bytes_async().

For resources, etag_out will be set to nil.

The data contained in the resulting #GBytes is always zero-terminated, but this is not included in the #GBytes length. The resulting #GBytes should be freed with g_bytes_unref() when no longer in use.

See g_file_load_bytes() for more information.

Parameters:

  • result (Gio::AsyncResult)

    a GAsync::Result provided to the callback

  • etag_out (String)

    a location to place the current entity tag for the file, or nil if the entity tag is not needed

Returns:

  • (GLib::Bytes)

    a #GBytes or nil and error is set

#load_contents(cancellable, contents, length, etag_out) ⇒ TrueClass

Loads the content of the file into memory. The data is always zero-terminated, but this is not included in the resultant length. The returned contents should be freed with g_free() when no longer needed.

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.

Parameters:

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • contents (Array<Integer>)

    a location to place the contents of the file

  • length (Integer)

    a location to place the length of the contents of the file, or nil if the length is not needed

  • etag_out (String)

    a location to place the current entity tag for the file, or nil if the entity tag is not needed

Returns:

  • (TrueClass)

    true if the file’s contents were successfully loaded. false if there were errors.

#load_contents_async(cancellable, callback, user_data) ⇒ nil

Starts an asynchronous load of the file’s contents.

For more details, see g_file_load_contents() which is the synchronous version of this call.

When the load operation has completed, callback will be called with user data. To finish the operation, call g_file_load_contents_finish() with the GAsync::Result returned by the callback.

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.

Parameters:

  • 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)

#load_contents_finish(res, contents, length, etag_out) ⇒ TrueClass

Finishes an asynchronous load of the file’s contents. The contents are placed in contents, and length is set to the size of the contents string. The contents should be freed with g_free() when no longer needed. If etag_out is present, it will be set to the new entity tag for the file.

Parameters:

  • res (Gio::AsyncResult)

    a GAsync::Result

  • contents (Array<Integer>)

    a location to place the contents of the file

  • length (Integer)

    a location to place the length of the contents of the file, or nil if the length is not needed

  • etag_out (String)

    a location to place the current entity tag for the file, or nil if the entity tag is not needed

Returns:

  • (TrueClass)

    true if the load was successful. If false and error is present, it will be set appropriately.

#load_partial_contents_async(cancellable, read_more_callback, callback, user_data) ⇒ nil

Reads the partial contents of a file. A GFile::ReadMoreCallback should be used to stop reading from the file when appropriate, else this function will behave exactly as g_file_load_contents_async(). This operation can be finished by g_file_load_partial_contents_finish().

Users of this function should be aware that user_data is passed to both the read_more_callback and the callback.

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.

Parameters:

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • read_more_callback (Gio::FileReadMoreCallback)

    a GFile::ReadMoreCallback to receive partial data and to specify whether further data should be read

  • callback (Gio::AsyncReadyCallback)

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

  • user_data (GObject)

    the data to pass to the callback functions

Returns:

  • (nil)

#load_partial_contents_finish(res, contents, length, etag_out) ⇒ TrueClass

Finishes an asynchronous partial load operation that was started with g_file_load_partial_contents_async(). The data is always zero-terminated, but this is not included in the resultant length. The returned contents should be freed with g_free() when no longer needed.

Parameters:

  • res (Gio::AsyncResult)

    a GAsync::Result

  • contents (Array<Integer>)

    a location to place the contents of the file

  • length (Integer)

    a location to place the length of the contents of the file, or nil if the length is not needed

  • etag_out (String)

    a location to place the current entity tag for the file, or nil if the entity tag is not needed

Returns:

  • (TrueClass)

    true if the load was successful. If false and error is present, it will be set appropriately.

#make_directory(file, cancellable) ⇒ TrueClass

Returns true on successful creation, false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true on successful creation, false otherwise.

#make_directory_async(file, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • 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)

#make_directory_finish(file, result) ⇒ TrueClass

Returns true on successful directory creation, false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true on successful directory creation, false otherwise.

#make_directory_with_parents(cancellable) ⇒ TrueClass

Creates a directory and any parent directories that may not exist similar to ‘mkdir -p’. If the file system does not support creating directories, this function will fail, setting error to %G_IO_ERROR_NOT_SUPPORTED. If the directory itself already exists, this function will fail setting error to %G_IO_ERROR_EXISTS, unlike the similar g_mkdir_with_parents().

For a local #GFile the newly created directories will have the default (current) ownership and permissions of the current process.

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

Parameters:

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if all directories have been successfully created, false

Returns true on the creation of a new symlink, false otherwise.

Parameters:

  • file (Gio::File)

    a #GFile with the name of the symlink to create

  • symlink_value (Gio::filename)

    a string with the path for the target of the new symlink

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true on the creation of a new symlink, false otherwise.

#measure_disk_usage(file, flags, cancellable, progress_callback, progress_data, disk_usage, num_dirs, num_files) ⇒ TrueClass

Returns true if successful, with the out parameters set. false otherwise, with error set.

Parameters:

  • file (Gio::File)

    a #GFile

  • flags (Gio::FileMeasureFlags)

    GFile::MeasureFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable

  • progress_callback (Gio::FileMeasureProgressCallback)

    a GFile::MeasureProgressCallback

  • progress_data (GObject)

    user_data for progress_callback

  • disk_usage (Integer)

    the number of bytes of disk space used

  • num_dirs (Integer)

    the number of directories encountered

  • num_files (Integer)

    the number of non-directories encountered

Returns:

  • (TrueClass)

    true if successful, with the out parameters set. false otherwise, with error set.

#measure_disk_usage_async(file, flags, io_priority, cancellable, progress_callback, progress_data, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    a #GFile

  • flags (Gio::FileMeasureFlags)

    GFile::MeasureFlags

  • io_priority (Integer)

    the [I/O priority] of the request

  • cancellable (Gio::Cancellable)

    optional #GCancellable

  • progress_callback (Gio::FileMeasureProgressCallback)

    a GFile::MeasureProgressCallback

  • progress_data (GObject)

    user_data for progress_callback

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when complete

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#measure_disk_usage_finish(file, result, disk_usage, num_dirs, num_files) ⇒ TrueClass

Returns true if successful, with the out parameters set. false otherwise, with error set.

Parameters:

  • file (Gio::File)

    a #GFile

  • result (Gio::AsyncResult)

    the GAsync::Result passed to your #GAsyncReadyCallback

  • disk_usage (Integer)

    the number of bytes of disk space used

  • num_dirs (Integer)

    the number of directories encountered

  • num_files (Integer)

    the number of non-directories encountered

Returns:

  • (TrueClass)

    true if successful, with the out parameters set. false otherwise, with error set.

#monitor(flags, cancellable) ⇒ Gio::FileMonitor

Obtains a file or directory monitor for the given file, depending on the type of the file.

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.

Parameters:

Returns:

  • (Gio::FileMonitor)

    a GFile::Monitor for the given file, or nil on error. Free the returned object with g_object_unref().

#monitor_dir(file, flags, cancellable) ⇒ Gio::FileMonitor

Returns a GFile::Monitor for the given file, or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileMonitor)

    a GFile::Monitor for the given file, or nil on error. Free the returned object with g_object_unref().

#monitor_directory(flags, cancellable) ⇒ Gio::FileMonitor

Obtains a directory monitor for the given file. This may fail if directory monitoring is not supported.

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.

It does not make sense for flags to contain %G_FILE_MONITOR_WATCH_HARD_LINKS, since hard links can not be made to directories. It is not possible to monitor all the files in a directory for changes made via hard links; if you want to do this then you must register individual watches with g_file_monitor().

Parameters:

Returns:

  • (Gio::FileMonitor)

    a GFile::Monitor for the given file, or nil on error. Free the returned object with g_object_unref().

#monitor_file(file, flags, cancellable) ⇒ Gio::FileMonitor

Returns a GFile::Monitor for the given file, or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileMonitor)

    a GFile::Monitor for the given file, or nil on error. Free the returned object with g_object_unref().

#mount_enclosing_volume(location, flags, mount_operation, cancellable, callback, user_data) ⇒ nil

Parameters:

  • location (Gio::File)

    input #GFile

  • flags (Gio::MountMountFlags)

    flags affecting the operation

  • mount_operation (Gio::MountOperation)

    a GMount::Operation or nil to avoid user interaction

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied, or nil

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#mount_enclosing_volume_finish(location, result) ⇒ TrueClass

Returns true if successful. If an error has occurred, this function will return false and set error appropriately if present.

Parameters:

Returns:

  • (TrueClass)

    true if successful. If an error has occurred, this function will return false and set error appropriately if present.

#mount_mountable(file, flags, mount_operation, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • flags (Gio::MountMountFlags)

    flags affecting the operation

  • mount_operation (Gio::MountOperation)

    a GMount::Operation, or nil to avoid user interaction

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied, or nil

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#mount_mountable_finish(file, result) ⇒ Gio::File

Returns a #GFile or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::File)

    a #GFile or nil on error. Free the returned object with g_object_unref().

#move(source, destination, flags, cancellable, progress_callback, progress_callback_data) ⇒ TrueClass

Returns true on successful move, false otherwise.

Parameters:

  • source (Gio::File)

    #GFile pointing to the source location

  • destination (Gio::File)

    #GFile pointing to the destination location

  • flags (Gio::FileCopyFlags)

    set of GFile::CopyFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • progress_callback (Gio::FileProgressCallback)

    GFile::ProgressCallback function for updates

  • progress_callback_data (GObject)

    gpointer to user data for the callback function

Returns:

  • (TrueClass)

    true on successful move, false otherwise.

#open_readwrite(file, cancellable) ⇒ Gio::FileIOStream

Returns GFile::IOStream or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileIOStream)

    GFile::IOStream or nil on error. Free the returned object with g_object_unref().

#open_readwrite_async(file, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • 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)

#open_readwrite_finish(file, res) ⇒ Gio::FileIOStream

Returns a GFile::IOStream or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileIOStream)

    a GFile::IOStream or nil on error. Free the returned object with g_object_unref().

#parentGio::File

Gets the parent directory for the file. If the file represents the root directory of the file system, then nil will be returned.

This call does no blocking I/O.

Returns:

  • (Gio::File)

    a #GFile structure to the parent of the given #GFile or nil if there is no parent. Free the returned object with g_object_unref().

#parse_nameString

Gets the parse name of the file. A parse name is a UTF-8 string that describes the file such that one can get the #GFile back using g_file_parse_name().

This is generally used to show the #GFile as a nice full-pathname kind of string in a user interface, like in a location entry.

For local files with names that can safely be converted to UTF-8 the pathname is used, otherwise the IRI is used (a form of URI that allows UTF-8 characters unescaped).

This call does no blocking I/O.

Returns:

  • (String)

    a string containing the #GFile’s parse name. The returned string should be freed with g_free() when no longer needed.

#pathGio::filename

Gets the local pathname for #GFile, if one exists. If non-nil, this is guaranteed to be an absolute, canonical path. It might contain symlinks.

This call does no blocking I/O.

Returns:

  • (Gio::filename)

    string containing the #GFile’s path, or nil if no such path exists. The returned string should be freed with g_free() when no longer needed.

#peek_pathGio::filename

Exactly like g_file_get_path(), but caches the result via g_object_set_qdata_full(). This is useful for example in C applications which mix ‘g_file_*` APIs with native ones. It also avoids an extra duplicated string when possible, so will be generally more efficient.

This call does no blocking I/O.

Returns:

  • (Gio::filename)

    string containing the #GFile’s path, or nil if no such path exists. The returned string is owned by file.

#poll_mountable(file, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied, or nil

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#poll_mountable_finish(file, result) ⇒ TrueClass

otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the operation finished successfully. false

#prefix_matches(prefix, file) ⇒ TrueClass

Returns true if the file’s parent, grandparent, etc is prefix, false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the file’s parent, grandparent, etc is prefix, false otherwise.

#query_default_handler(cancellable) ⇒ Gio::AppInfo

Returns the GApp::Info that is registered as the default application to handle the file specified by file.

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.

Parameters:

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (Gio::AppInfo)

    a GApp::Info if the handle was found, nil if there were errors. When you are done with it, release it with g_object_unref()

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

Async version of g_file_query_default_handler().

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 done

  • user_data (GObject)

    data to pass to callback

Returns:

  • (nil)

#query_default_handler_finish(result) ⇒ Gio::AppInfo

Finishes a g_file_query_default_handler_async() operation.

Parameters:

Returns:

  • (Gio::AppInfo)

    a GApp::Info if the handle was found, nil if there were errors. When you are done with it, release it with g_object_unref()

#query_exists(cancellable) ⇒ TrueClass

Utility function to check if a particular file exists. This is implemented using g_file_query_info() and as such does blocking I/O.

Note that in many cases it is [racy to first check for file existence](en.wikipedia.org/wiki/Time_of_check_to_time_of_use) and then execute something based on the outcome of that, because the file might have been created or removed in between the operations. The general approach to handling that is to not check, but just do the operation and handle the errors as they come.

As an example of race-free checking, take the case of reading a file, and if it doesn’t exist, creating it. There are two racy versions: read it, and on error create it; and: check if it exists, if not create it. These can both result in two processes creating the file (with perhaps a partially written file as the result). The correct approach is to always try to create the file with g_file_create() which will either atomically create the file or fail with a %G_IO_ERROR_EXISTS error.

However, in many cases an existence check is useful in a user interface, for instance to make a menu item sensitive/insensitive, so that you don’t have to fool users that something is possible and then just show an error dialog. If you do this, you should make sure to also handle the errors that can happen due to races when you execute the operation.

Parameters:

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if the file exists (and can be detected without error), false otherwise (or if cancelled).

#query_file_type(flags, cancellable) ⇒ Gio::FileType

Utility function to inspect the GFile::Type of a file. This is implemented using g_file_query_info() and as such does blocking I/O.

The primary use case of this method is to check if a file is a regular file, directory, or symlink.

Parameters:

Returns:

  • (Gio::FileType)

    The GFile::Type of the file and #G_FILE_TYPE_UNKNOWN if the file does not exist

#query_filesystem_info(file, attributes, cancellable) ⇒ Gio::FileInfo

Returns a GFile::Info or nil if there was an error. Free the returned object with g_object_unref().

Parameters:

  • file (Gio::File)

    input #GFile

  • attributes (String)

    an attribute query string

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (Gio::FileInfo)

    a GFile::Info or nil if there was an error. Free the returned object with g_object_unref().

#query_filesystem_info_async(file, attributes, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • attributes (String)

    an attribute query string

  • 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)

#query_filesystem_info_finish(file, res) ⇒ Gio::FileInfo

Returns GFile::Info for given file or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileInfo)

    GFile::Info for given file or nil on error. Free the returned object with g_object_unref().

#query_info(file, attributes, flags, cancellable) ⇒ Gio::FileInfo

Returns a GFile::Info for the given file, or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileInfo)

    a GFile::Info for the given file, or nil on error. Free the returned object with g_object_unref().

#query_info_async(file, attributes, flags, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • attributes (String)

    an attribute query string

  • flags (Gio::FileQueryInfoFlags)

    a set of GFile::QueryInfoFlags

  • 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)

#query_info_finish(file, res) ⇒ Gio::FileInfo

Returns GFile::Info for given file or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileInfo)

    GFile::Info for given file or nil on error. Free the returned object with g_object_unref().

#query_settable_attributes(file, cancellable) ⇒ Gio::FileAttributeInfoList

Returns a GFile::AttributeInfoList describing the settable attributes. When you are done with it, release it with g_file_attribute_info_list_unref().

Parameters:

Returns:

  • (Gio::FileAttributeInfoList)

    a GFile::AttributeInfoList describing the settable attributes. When you are done with it, release it with g_file_attribute_info_list_unref()

#query_writable_namespaces(file, cancellable) ⇒ Gio::FileAttributeInfoList

Returns a GFile::AttributeInfoList describing the writable namespaces. When you are done with it, release it with g_file_attribute_info_list_unref().

Parameters:

Returns:

  • (Gio::FileAttributeInfoList)

    a GFile::AttributeInfoList describing the writable namespaces. When you are done with it, release it with g_file_attribute_info_list_unref()

#read(cancellable) ⇒ Gio::FileInputStream

Opens a file for reading. The result is a GFile::InputStream that can be used to read the contents of the file.

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.

If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be returned. If the file is a directory, the %G_IO_ERROR_IS_DIRECTORY error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters:

Returns:

  • (Gio::FileInputStream)

    GFile::InputStream or nil on error. Free the returned object with g_object_unref().

#read_async(file, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • 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)

#read_finish(file, res) ⇒ Gio::FileInputStream

Returns a GFile::InputStream or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileInputStream)

    a GFile::InputStream or nil on error. Free the returned object with g_object_unref().

#read_fn(file, cancellable) ⇒ Gio::FileInputStream

Returns GFile::InputStream or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileInputStream)

    GFile::InputStream or nil on error. Free the returned object with g_object_unref().

#replace(file, etag, make_backup, flags, cancellable) ⇒ Gio::FileOutputStream

Returns a GFile::OutputStream or nil on error. Free the returned object with g_object_unref().

Parameters:

  • file (Gio::File)

    input #GFile

  • etag (String)

    an optional [entity tag] for the current #GFile, or #NULL to ignore

  • make_backup (TrueClass)

    true if a backup should be created

  • flags (Gio::FileCreateFlags)

    a set of GFile::CreateFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (Gio::FileOutputStream)

    a GFile::OutputStream or nil on error. Free the returned object with g_object_unref().

#replace_async(file, etag, make_backup, flags, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • etag (String)

    an [entity tag] for the current #GFile, or nil to ignore

  • make_backup (TrueClass)

    true if a backup should be created

  • flags (Gio::FileCreateFlags)

    a set of GFile::CreateFlags

  • 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)

#replace_contents(contents, length, etag, make_backup, flags, new_etag, cancellable) ⇒ TrueClass

Replaces the contents of file with contents of length bytes.

If etag is specified (not nil), any existing file must have that etag, or the error %G_IO_ERROR_WRONG_ETAG will be returned.

If make_backup is true, this function will attempt to make a backup of file. Internally, it uses g_file_replace(), so will try to replace the file contents in the safest way possible. For example, atomic renames are used when replacing local files’ contents.

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.

The returned new_etag can be used to verify that the file hasn’t changed the next time it is saved over.

Parameters:

  • contents (Array<Integer>)

    a string containing the new contents for file

  • length (Integer)

    the length of contents in bytes

  • etag (String)

    the old [entity-tag] for the document, or nil

  • make_backup (TrueClass)

    true if a backup should be created

  • flags (Gio::FileCreateFlags)

    a set of GFile::CreateFlags

  • new_etag (String)

    a location to a new [entity tag] for the document. This should be freed with g_free() when no longer needed, or nil

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if successful. If an error has occurred, this function will return false and set error appropriately if present.

#replace_contents_async(contents, length, etag, make_backup, flags, cancellable, callback, user_data) ⇒ nil

Starts an asynchronous replacement of file with the given contents of length bytes. etag will replace the document’s current entity tag.

When this operation has completed, callback will be called with user_user data, and the operation can be finalized with g_file_replace_contents_finish().

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.

If make_backup is true, this function will attempt to make a backup of file.

Note that no copy of contents will be made, so it must stay valid until callback is called. See g_file_replace_contents_bytes_async() for a #GBytes version that will automatically hold a reference to the contents (without copying) for the duration of the call.

Parameters:

  • contents (Array<Integer>)

    string of contents to replace the file with

  • length (Integer)

    the length of contents in bytes

  • etag (String)

    a new [entity tag] for the file, or nil

  • make_backup (TrueClass)

    true if a backup should be created

  • flags (Gio::FileCreateFlags)

    a set of GFile::CreateFlags

  • 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)

#replace_contents_bytes_async(contents, etag, make_backup, flags, cancellable, callback, user_data) ⇒ nil

Same as g_file_replace_contents_async() but takes a #GBytes input instead. This function will keep a ref on contents until the operation is done. Unlike g_file_replace_contents_async() this allows forgetting about the content without waiting for the callback.

When this operation has completed, callback will be called with user_user data, and the operation can be finalized with g_file_replace_contents_finish().

Parameters:

  • contents (GLib::Bytes)

    a #GBytes

  • etag (String)

    a new [entity tag] for the file, or nil

  • make_backup (TrueClass)

    true if a backup should be created

  • flags (Gio::FileCreateFlags)

    a set of GFile::CreateFlags

  • 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)

#replace_contents_finish(res, new_etag) ⇒ TrueClass

Finishes an asynchronous replace of the given file. See g_file_replace_contents_async(). Sets new_etag to the new entity tag for the document, if present.

Parameters:

  • res (Gio::AsyncResult)

    a GAsync::Result

  • new_etag (String)

    a location of a new [entity tag] for the document. This should be freed with g_free() when it is no longer needed, or nil

Returns:

  • (TrueClass)

    true on success, false on failure.

#replace_finish(file, res) ⇒ Gio::FileOutputStream

Returns a GFile::OutputStream, or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileOutputStream)

    a GFile::OutputStream, or nil on error. Free the returned object with g_object_unref().

#replace_readwrite(file, etag, make_backup, flags, cancellable) ⇒ Gio::FileIOStream

Returns a GFile::IOStream or nil on error. Free the returned object with g_object_unref().

Parameters:

  • file (Gio::File)

    a #GFile

  • etag (String)

    an optional [entity tag] for the current #GFile, or #NULL to ignore

  • make_backup (TrueClass)

    true if a backup should be created

  • flags (Gio::FileCreateFlags)

    a set of GFile::CreateFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (Gio::FileIOStream)

    a GFile::IOStream or nil on error. Free the returned object with g_object_unref().

#replace_readwrite_async(file, etag, make_backup, flags, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • etag (String)

    an [entity tag] for the current #GFile, or nil to ignore

  • make_backup (TrueClass)

    true if a backup should be created

  • flags (Gio::FileCreateFlags)

    a set of GFile::CreateFlags

  • 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)

#replace_readwrite_finish(file, res) ⇒ Gio::FileIOStream

Returns a GFile::IOStream, or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::FileIOStream)

    a GFile::IOStream, or nil on error. Free the returned object with g_object_unref().

#resolve_relative_path(file, relative_path) ⇒ Gio::File

Returns #GFile to the resolved path. nil if relative_path is nil or if file is invalid. Free the returned object with g_object_unref().

Parameters:

  • file (Gio::File)

    input #GFile

  • relative_path (Gio::filename)

    a given relative path string

Returns:

  • (Gio::File)

    #GFile to the resolved path. nil if relative_path is nil or if file is invalid. Free the returned object with g_object_unref().

#set_attribute(file, attribute, type, value_p, flags, cancellable) ⇒ TrueClass

Returns true if the attribute was set, false otherwise.

Parameters:

  • file (Gio::File)

    input #GFile

  • attribute (String)

    a string containing the attribute’s name

  • type (Gio::FileAttributeType)

    The type of the attribute

  • value_p (GObject)

    a pointer to the value (or the pointer itself if the type is a pointer type)

  • flags (Gio::FileQueryInfoFlags)

    a set of GFile::QueryInfoFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if the attribute was set, false otherwise.

#set_attribute_byte_string(attribute, value, flags, cancellable) ⇒ TrueClass

Sets attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to value. If attribute is of a different type, this operation will fail, returning false.

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.

Parameters:

  • attribute (String)

    a string containing the attribute’s name

  • value (String)

    a string containing the attribute’s new value

  • flags (Gio::FileQueryInfoFlags)

    a GFile::QueryInfoFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if the attribute was successfully set to value in the file, false otherwise.

#set_attribute_int32(attribute, value, flags, cancellable) ⇒ TrueClass

Sets attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to value. If attribute is of a different type, this operation will fail.

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.

Parameters:

  • attribute (String)

    a string containing the attribute’s name

  • value (Integer)

    a #gint32 containing the attribute’s new value

  • flags (Gio::FileQueryInfoFlags)

    a GFile::QueryInfoFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if the attribute was successfully set to value in the file, false otherwise.

#set_attribute_int64(attribute, value, flags, cancellable) ⇒ TrueClass

Sets attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to value. If attribute is of a different type, this operation will fail.

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.

Parameters:

  • attribute (String)

    a string containing the attribute’s name

  • value (Integer)

    a #guint64 containing the attribute’s new value

  • flags (Gio::FileQueryInfoFlags)

    a GFile::QueryInfoFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if the attribute was successfully set, false otherwise.

#set_attribute_string(attribute, value, flags, cancellable) ⇒ TrueClass

Sets attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to value. If attribute is of a different type, this operation will fail.

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.

Parameters:

  • attribute (String)

    a string containing the attribute’s name

  • value (String)

    a string containing the attribute’s value

  • flags (Gio::FileQueryInfoFlags)

    GFile::QueryInfoFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if the attribute was successfully set, false otherwise.

#set_attribute_uint32(attribute, value, flags, cancellable) ⇒ TrueClass

Sets attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to value. If attribute is of a different type, this operation will fail.

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.

Parameters:

  • attribute (String)

    a string containing the attribute’s name

  • value (Integer)

    a #guint32 containing the attribute’s new value

  • flags (Gio::FileQueryInfoFlags)

    a GFile::QueryInfoFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if the attribute was successfully set to value in the file, false otherwise.

#set_attribute_uint64(attribute, value, flags, cancellable) ⇒ TrueClass

Sets attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to value. If attribute is of a different type, this operation will fail.

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.

Parameters:

  • attribute (String)

    a string containing the attribute’s name

  • value (Integer)

    a #guint64 containing the attribute’s new value

  • flags (Gio::FileQueryInfoFlags)

    a GFile::QueryInfoFlags

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true if the attribute was successfully set to value in the file, false otherwise.

#set_attributes_async(file, info, flags, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • info (Gio::FileInfo)

    a GFile::Info

  • flags (Gio::FileQueryInfoFlags)

    a GFile::QueryInfoFlags

  • 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

  • user_data (GObject)

    a #gpointer

Returns:

  • (nil)

#set_attributes_finish(file, result, info) ⇒ TrueClass

Returns true if the attributes were set correctly, false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the attributes were set correctly, false otherwise.

#set_attributes_from_info(file, info, flags, cancellable) ⇒ TrueClass

Returns false if there was any error, true otherwise.

Parameters:

Returns:

  • (TrueClass)

    false if there was any error, true otherwise.

#set_display_name(file, display_name, cancellable) ⇒ Gio::File

Returns a #GFile specifying what file was renamed to, or nil if there was an error. Free the returned object with g_object_unref().

Parameters:

  • file (Gio::File)

    input #GFile

  • display_name (String)

    a string

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (Gio::File)

    a #GFile specifying what file was renamed to, or nil if there was an error. Free the returned object with g_object_unref().

#set_display_name_async(file, display_name, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • display_name (String)

    a string

  • 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)

#set_display_name_finish(file, res) ⇒ Gio::File

Returns a #GFile or nil on error. Free the returned object with g_object_unref().

Parameters:

Returns:

  • (Gio::File)

    a #GFile or nil on error. Free the returned object with g_object_unref().

#start_mountable(file, flags, start_operation, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • flags (Gio::DriveStartFlags)

    flags affecting the operation

  • start_operation (Gio::MountOperation)

    a GMount::Operation, or nil to avoid user interaction

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied, or nil

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#start_mountable_finish(file, result) ⇒ TrueClass

otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the operation finished successfully. false

#stop_mountable(file, flags, mount_operation, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • flags (Gio::MountUnmountFlags)

    flags affecting the operation

  • mount_operation (Gio::MountOperation)

    a GMount::Operation, or nil to avoid user interaction.

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied, or nil

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#stop_mountable_finish(file, result) ⇒ TrueClass

Returns true if the operation finished successfully. false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the operation finished successfully. false otherwise.

#supports_thread_contextsTrueClass

Checks if file supports [thread-default contexts]. If this returns false, you cannot perform asynchronous operations on file in a thread that has a thread-default context.

Returns:

  • (TrueClass)

    Whether or not file supports thread-default contexts.

#trash(file, cancellable) ⇒ TrueClass

Returns true on successful trash, false otherwise.

Parameters:

  • file (Gio::File)

    #GFile to send to trash

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

Returns:

  • (TrueClass)

    true on successful trash, false otherwise.

#trash_async(file, io_priority, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • 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)

#trash_finish(file, result) ⇒ TrueClass

Returns true on successful trash, false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true on successful trash, false otherwise.

#unmount_mountable(file, flags, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • flags (Gio::MountUnmountFlags)

    flags affecting the operation

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied, or nil

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#unmount_mountable_finish(file, result) ⇒ TrueClass

Returns true if the operation finished successfully. false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the operation finished successfully. false otherwise.

#unmount_mountable_with_operation(file, flags, mount_operation, cancellable, callback, user_data) ⇒ nil

Parameters:

  • file (Gio::File)

    input #GFile

  • flags (Gio::MountUnmountFlags)

    flags affecting the operation

  • mount_operation (Gio::MountOperation)

    a GMount::Operation, or nil to avoid user interaction

  • cancellable (Gio::Cancellable)

    optional #GCancellable object, nil to ignore

  • callback (Gio::AsyncReadyCallback)

    a GAsync::ReadyCallback to call when the request is satisfied, or nil

  • user_data (GObject)

    the data to pass to callback function

Returns:

  • (nil)

#unmount_mountable_with_operation_finish(file, result) ⇒ TrueClass

Returns true if the operation finished successfully. false otherwise.

Parameters:

Returns:

  • (TrueClass)

    true if the operation finished successfully. false otherwise.

#uriString

Gets the URI for the file.

This call does no blocking I/O.

Returns:

  • (String)

    a string containing the #GFile’s URI. The returned string should be freed with g_free() when no longer needed.

#uri_schemeString

Gets the URI scheme for a #GFile. RFC 3986 decodes the scheme as: |[ URI = scheme “:” hier-part [ “?” query ] [ “#” fragment ] ]| Common schemes include “file”, “http”, “ftp”, etc.

This call does no blocking I/O.

Returns:

  • (String)

    a string containing the URI scheme for the given #GFile. The returned string should be freed with g_free() when no longer needed.