Gio.File

g GObject.GInterface GObject.GInterface Gio.File Gio.File GObject.GInterface->Gio.File

Implementations:

None

Methods

class

new_build_filenamev (args)

class

new_for_commandline_arg (arg)

class

new_for_commandline_arg_and_cwd (arg, cwd)

class

new_for_path (path)

class

new_for_uri (uri)

class

new_tmp (tmpl)

class

new_tmp_async (tmpl, io_priority, cancellable, callback, *user_data)

class

new_tmp_dir_async (tmpl, io_priority, cancellable, callback, *user_data)

class

new_tmp_dir_finish (result)

class

new_tmp_finish (result)

class

parse_name (parse_name)

append_to (flags, cancellable)

append_to_async (flags, io_priority, cancellable, callback, *user_data)

append_to_finish (res)

build_attribute_list_for_copy (flags, cancellable)

copy (destination, flags, cancellable, progress_callback, *progress_callback_data)

copy_async (destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data)

copy_attributes (destination, flags, cancellable)

copy_finish (res)

create (flags, cancellable)

create_async (flags, io_priority, cancellable, callback, *user_data)

create_finish (res)

create_readwrite (flags, cancellable)

create_readwrite_async (flags, io_priority, cancellable, callback, *user_data)

create_readwrite_finish (res)

delete (cancellable)

delete_async (io_priority, cancellable, callback, *user_data)

delete_finish (result)

dup ()

eject_mountable (flags, cancellable, callback, *user_data)

eject_mountable_finish (result)

eject_mountable_with_operation (flags, mount_operation, cancellable, callback, *user_data)

eject_mountable_with_operation_finish (result)

enumerate_children (attributes, flags, cancellable)

enumerate_children_async (attributes, flags, io_priority, cancellable, callback, *user_data)

enumerate_children_finish (res)

equal (file2)

find_enclosing_mount (cancellable)

find_enclosing_mount_async (io_priority, cancellable, callback, *user_data)

find_enclosing_mount_finish (res)

get_basename ()

get_child (name)

get_child_for_display_name (display_name)

get_parent ()

get_parse_name ()

get_path ()

get_relative_path (descendant)

get_uri ()

get_uri_scheme ()

has_parent (parent)

has_prefix (prefix)

has_uri_scheme (uri_scheme)

hash ()

is_native ()

load_bytes (cancellable)

load_bytes_async (cancellable, callback, *user_data)

load_bytes_finish (result)

load_contents (cancellable)

load_contents_async (cancellable, callback, *user_data)

load_contents_finish (res)

load_partial_contents_finish (res)

make_directory (cancellable)

make_directory_async (io_priority, cancellable, callback, *user_data)

make_directory_finish (result)

make_directory_with_parents (cancellable)

make_symbolic_link (symlink_value, cancellable)

make_symbolic_link_async (symlink_value, io_priority, cancellable, callback, *user_data)

make_symbolic_link_finish (result)

measure_disk_usage (flags, cancellable, progress_callback, *progress_data)

measure_disk_usage_finish (result)

monitor (flags, cancellable)

monitor_directory (flags, cancellable)

monitor_file (flags, cancellable)

mount_enclosing_volume (flags, mount_operation, cancellable, callback, *user_data)

mount_enclosing_volume_finish (result)

mount_mountable (flags, mount_operation, cancellable, callback, *user_data)

mount_mountable_finish (result)

move (destination, flags, cancellable, progress_callback, *progress_callback_data)

move_async (destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data)

move_finish (result)

open_readwrite (cancellable)

open_readwrite_async (io_priority, cancellable, callback, *user_data)

open_readwrite_finish (res)

peek_path ()

poll_mountable (cancellable, callback, *user_data)

poll_mountable_finish (result)

query_default_handler (cancellable)

query_default_handler_async (io_priority, cancellable, callback, *user_data)

query_default_handler_finish (result)

query_exists (cancellable)

query_file_type (flags, cancellable)

query_filesystem_info (attributes, cancellable)

query_filesystem_info_async (attributes, io_priority, cancellable, callback, *user_data)

query_filesystem_info_finish (res)

query_info (attributes, flags, cancellable)

query_info_async (attributes, flags, io_priority, cancellable, callback, *user_data)

query_info_finish (res)

query_settable_attributes (cancellable)

query_writable_namespaces (cancellable)

read (cancellable)

read_async (io_priority, cancellable, callback, *user_data)

read_finish (res)

replace (etag, make_backup, flags, cancellable)

replace_async (etag, make_backup, flags, io_priority, cancellable, callback, *user_data)

replace_contents (contents, etag, make_backup, flags, cancellable)

replace_contents_async (contents, etag, make_backup, flags, cancellable, callback, *user_data)

replace_contents_bytes_async (contents, etag, make_backup, flags, cancellable, callback, *user_data)

replace_contents_finish (res)

replace_finish (res)

replace_readwrite (etag, make_backup, flags, cancellable)

replace_readwrite_async (etag, make_backup, flags, io_priority, cancellable, callback, *user_data)

replace_readwrite_finish (res)

resolve_relative_path (relative_path)

set_attribute (attribute, type, value_p, flags, cancellable)

set_attribute_byte_string (attribute, value, flags, cancellable)

set_attribute_int32 (attribute, value, flags, cancellable)

set_attribute_int64 (attribute, value, flags, cancellable)

set_attribute_string (attribute, value, flags, cancellable)

set_attribute_uint32 (attribute, value, flags, cancellable)

set_attribute_uint64 (attribute, value, flags, cancellable)

set_attributes_async (info, flags, io_priority, cancellable, callback, *user_data)

set_attributes_finish (result)

set_attributes_from_info (info, flags, cancellable)

set_display_name (display_name, cancellable)

set_display_name_async (display_name, io_priority, cancellable, callback, *user_data)

set_display_name_finish (res)

start_mountable (flags, start_operation, cancellable, callback, *user_data)

start_mountable_finish (result)

stop_mountable (flags, mount_operation, cancellable, callback, *user_data)

stop_mountable_finish (result)

supports_thread_contexts ()

trash (cancellable)

trash_async (io_priority, cancellable, callback, *user_data)

trash_finish (result)

unmount_mountable (flags, cancellable, callback, *user_data)

unmount_mountable_finish (result)

unmount_mountable_with_operation (flags, mount_operation, cancellable, callback, *user_data)

unmount_mountable_with_operation_finish (result)

Virtual Methods

do_append_to (flags, cancellable)

do_append_to_async (flags, io_priority, cancellable, callback, *user_data)

do_append_to_finish (res)

do_copy (destination, flags, cancellable, progress_callback, progress_callback_data)

do_copy_async (destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data)

do_copy_finish (res)

do_create (flags, cancellable)

do_create_async (flags, io_priority, cancellable, callback, *user_data)

do_create_finish (res)

do_create_readwrite (flags, cancellable)

do_create_readwrite_async (flags, io_priority, cancellable, callback, *user_data)

do_create_readwrite_finish (res)

do_delete_file (cancellable)

do_delete_file_async (io_priority, cancellable, callback, *user_data)

do_delete_file_finish (result)

do_dup ()

do_eject_mountable (flags, cancellable, callback, *user_data)

do_eject_mountable_finish (result)

do_eject_mountable_with_operation (flags, mount_operation, cancellable, callback, *user_data)

do_eject_mountable_with_operation_finish (result)

do_enumerate_children (attributes, flags, cancellable)

do_enumerate_children_async (attributes, flags, io_priority, cancellable, callback, *user_data)

do_enumerate_children_finish (res)

do_equal (file2)

do_find_enclosing_mount (cancellable)

do_find_enclosing_mount_async (io_priority, cancellable, callback, *user_data)

do_find_enclosing_mount_finish (res)

do_get_basename ()

do_get_child_for_display_name (display_name)

do_get_parent ()

do_get_parse_name ()

do_get_path ()

do_get_relative_path (descendant)

do_get_uri ()

do_get_uri_scheme ()

do_has_uri_scheme (uri_scheme)

do_hash ()

do_is_native ()

do_make_directory (cancellable)

do_make_directory_async (io_priority, cancellable, callback, *user_data)

do_make_directory_finish (result)

do_make_symbolic_link (symlink_value, cancellable)

do_make_symbolic_link_async (symlink_value, io_priority, cancellable, callback, *user_data)

do_make_symbolic_link_finish (result)

do_measure_disk_usage (flags, cancellable, progress_callback, progress_data)

do_measure_disk_usage_finish (result)

do_monitor_dir (flags, cancellable)

do_monitor_file (flags, cancellable)

do_mount_enclosing_volume (flags, mount_operation, cancellable, callback, *user_data)

do_mount_enclosing_volume_finish (result)

do_mount_mountable (flags, mount_operation, cancellable, callback, *user_data)

do_mount_mountable_finish (result)

do_move (destination, flags, cancellable, progress_callback, progress_callback_data)

do_move_async (destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data)

do_move_finish (result)

do_open_readwrite (cancellable)

do_open_readwrite_async (io_priority, cancellable, callback, *user_data)

do_open_readwrite_finish (res)

do_poll_mountable (cancellable, callback, *user_data)

do_poll_mountable_finish (result)

do_prefix_matches (file)

do_query_filesystem_info (attributes, cancellable)

do_query_filesystem_info_async (attributes, io_priority, cancellable, callback, *user_data)

do_query_filesystem_info_finish (res)

do_query_info (attributes, flags, cancellable)

do_query_info_async (attributes, flags, io_priority, cancellable, callback, *user_data)

do_query_info_finish (res)

do_query_settable_attributes (cancellable)

do_query_writable_namespaces (cancellable)

do_read_async (io_priority, cancellable, callback, *user_data)

do_read_finish (res)

do_read_fn (cancellable)

do_replace (etag, make_backup, flags, cancellable)

do_replace_async (etag, make_backup, flags, io_priority, cancellable, callback, *user_data)

do_replace_finish (res)

do_replace_readwrite (etag, make_backup, flags, cancellable)

do_replace_readwrite_async (etag, make_backup, flags, io_priority, cancellable, callback, *user_data)

do_replace_readwrite_finish (res)

do_resolve_relative_path (relative_path)

do_set_attribute (attribute, type, value_p, flags, cancellable)

do_set_attributes_async (info, flags, io_priority, cancellable, callback, *user_data)

do_set_attributes_finish (result)

do_set_attributes_from_info (info, flags, cancellable)

do_set_display_name (display_name, cancellable)

do_set_display_name_async (display_name, io_priority, cancellable, callback, *user_data)

do_set_display_name_finish (res)

do_start_mountable (flags, start_operation, cancellable, callback, *user_data)

do_start_mountable_finish (result)

do_stop_mountable (flags, mount_operation, cancellable, callback, *user_data)

do_stop_mountable_finish (result)

do_trash (cancellable)

do_trash_async (io_priority, cancellable, callback, *user_data)

do_trash_finish (result)

do_unmount_mountable (flags, cancellable, callback, *user_data)

do_unmount_mountable_finish (result)

do_unmount_mountable_with_operation (flags, mount_operation, cancellable, callback, *user_data)

do_unmount_mountable_with_operation_finish (result)

Properties

None

Signals

None

Fields

None

Class Details

class Gio.File
Bases:

GObject.GInterface

Structure:

Gio.FileIface

GFile is a high level abstraction for manipulating files on a virtual file system. GFile``s 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 [class`Gio`.InputStream] and [class`Gio`.OutputStream]).

To construct a GFile, you can use:

  • [func`Gio`.File.new_for_path] if you have a path.

  • [func`Gio`.File.new_for_uri] if you have a URI.

  • [func`Gio`.File.new_for_commandline_arg] or [func`Gio`.File.new_for_commandline_arg_and_cwd] for a command line argument.

  • [func`Gio`.File.new_tmp] to create a temporary file from a template.

  • [func`Gio`.File.new_tmp_async] to asynchronously create a temporary file.

  • [func`Gio`.File.new_tmp_dir_async] to asynchronously create a temporary directory.

  • [func`Gio`.File.parse_name] from a UTF-8 string gotten from [method`Gio`.File.get_parse_name].

  • [func`Gio`.File.new_build_filename] or [func`Gio`.File.new_build_filenamev] 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 ``GFile``s are extensible it could also be something else that corresponds to a pathname in a userspace implementation of a filesystem.

GFile``s 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 [method`Gio`.File.get_parent] to get an identifier for the parent directory, [method`Gio`.File.get_child] to get a child within a directory, and [method`Gio`.File.resolve_relative_path] to resolve a relative path between two ``GFile``s. There can be multiple hierarchies, so you may not end up at the same root if you repeatedly call [method`Gio`.File.get_parent] on two different files.

All GFile``s have a basename (get with [method`Gio`.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 [method`Gio`.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 GFile``s 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 ``GFile``s 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 ``GFile``s.

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 [callback`Gio`.AsyncReadyCallback] which is then used to finalize the operation, producing a [iface`Gio`.AsyncResult] 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 for more.

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

  • [method`Gio`.File.mount_mountable] to mount a mountable file.

  • [method`Gio`.File.unmount_mountable_with_operation] to unmount a mountable file.

  • [method`Gio`.File.eject_mountable_with_operation] to eject a mountable file.

Entity Tags

One notable feature of GFile``s 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 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>`__ for HTTP ``ETag headers, which are a very similar concept.

classmethod new_build_filenamev(args)[source]
Parameters:

args ([str]) – None-terminated array of strings containing the path elements.

Returns:

a new Gio.File

Return type:

Gio.File

Constructs a Gio.File from a vector of elements using the correct separator for filenames.

Using this function is equivalent to calling GLib.build_filenamev(), followed by Gio.File.new_for_path() on the result.

New in version 2.78.

classmethod new_for_commandline_arg(arg)[source]
Parameters:

arg (str) – a command line string

Returns:

a new Gio.File. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Creates a Gio.File with the given argument from the command line. The value of arg can be either a URI, an absolute path or a relative path resolved relative to the current working directory. This operation never fails, but the returned object might not support any I/O operation if arg points to a malformed path.

Note that on Windows, this function expects its argument to be in UTF-8 – not the system code page. This means that you should not use this function with string from argv as it is passed to main(). g_win32_get_command_line() will return a UTF-8 version of the commandline. Gio.Application also uses UTF-8 but Gio.ApplicationCommandLine.create_file_for_arg() may be more useful for you there. It is also always possible to use this function with GLib.OptionContext arguments of type GLib.OptionArg.FILENAME.

classmethod new_for_commandline_arg_and_cwd(arg, cwd)[source]
Parameters:
  • arg (str) – a command line string

  • cwd (str) – the current working directory of the commandline

Returns:

a new Gio.File

Return type:

Gio.File

Creates a Gio.File with the given argument from the command line.

This function is similar to Gio.File.new_for_commandline_arg() except that it allows for passing the current working directory as an argument instead of using the current working directory of the process.

This is useful if the commandline argument was given in a context other than the invocation of the current process.

See also Gio.ApplicationCommandLine.create_file_for_arg().

New in version 2.36.

classmethod new_for_path(path)[source]
Parameters:

path (str) – a string containing a relative or absolute path. The string must be encoded in the glib filename encoding.

Returns:

a new Gio.File for the given path. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Constructs a Gio.File for a given path. This operation never fails, but the returned object might not support any I/O operation if path is malformed.

classmethod new_for_uri(uri)[source]
Parameters:

uri (str) – a UTF-8 string containing a URI

Returns:

a new Gio.File for the given uri. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Constructs a Gio.File for a given URI. This operation never fails, but the returned object might not support any I/O operation if uri is malformed or if the uri type is not supported.

classmethod new_tmp(tmpl)[source]
Parameters:

tmpl (str or None) – Template for the file name, as in GLib.file_open_tmp(), or None for a default template

Raises:

GLib.Error

Returns:

a new Gio.File. Free the returned object with GObject.Object.unref().

iostream:

on return, a Gio.FileIOStream for the created file

Return type:

(Gio.File, iostream: Gio.FileIOStream)

Opens a file in the preferred directory for temporary files (as returned by GLib.get_tmp_dir()) and returns a Gio.File and Gio.FileIOStream pointing to it.

tmpl should be a string in the GLib file name encoding containing a sequence of six ‘X’ characters, and containing no directory components. If it is None, a default template is used.

Unlike the other Gio.File constructors, this will return None if a temporary file could not be created.

New in version 2.32.

classmethod new_tmp_async(tmpl, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously opens a file in the preferred directory for temporary files (as returned by GLib.get_tmp_dir()) as Gio.File.new_tmp().

tmpl should be a string in the GLib file name encoding containing a sequence of six ‘X’ characters, and containing no directory components. If it is None, a default template is used.

New in version 2.74.

classmethod new_tmp_dir_async(tmpl, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously creates a directory in the preferred directory for temporary files (as returned by GLib.get_tmp_dir()) as GLib.Dir.make_tmp().

tmpl should be a string in the GLib file name encoding containing a sequence of six ‘X’ characters, and containing no directory components. If it is None, a default template is used.

New in version 2.74.

classmethod new_tmp_dir_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a new Gio.File. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Finishes a temporary directory creation started by Gio.File.new_tmp_dir_async().

New in version 2.74.

classmethod new_tmp_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a new Gio.File. Free the returned object with GObject.Object.unref().

iostream:

on return, a Gio.FileIOStream for the created file

Return type:

(Gio.File, iostream: Gio.FileIOStream)

Finishes a temporary file creation started by Gio.File.new_tmp_async().

New in version 2.74.

classmethod parse_name(parse_name)[source]
Parameters:

parse_name (str) – a file name or path to be parsed

Returns:

a new Gio.File.

Return type:

Gio.File

Constructs a Gio.File with the given parse_name (i.e. something given by Gio.File.get_parse_name()). This operation never fails, but the returned object might not support any I/O operation if the parse_name cannot be parsed.

append_to(flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.FileOutputStream, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Gets an output stream for appending data to the file. If the file doesn’t already exist it is created.

By default files created are generally readable by everyone, but if you pass Gio.FileCreateFlags.PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

Some file systems don’t allow all file names, and may return an Gio.IOErrorEnum.INVALID_FILENAME error. If the file is a directory the Gio.IOErrorEnum.IS_DIRECTORY error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

append_to_async(flags, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously opens self for appending.

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

When the operation is finished, callback will be called. You can then call Gio.File.append_to_finish() to get the result of the operation.

append_to_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – Gio.AsyncResult

Raises:

GLib.Error

Returns:

a valid Gio.FileOutputStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Finishes an asynchronous file append operation started with Gio.File.append_to_async().

build_attribute_list_for_copy(flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

an attribute query string for Gio.File.query_info(), or None if an error occurs.

Return type:

str

Prepares the file attribute query string for copying to self.

This function prepares an attribute query string to be passed to Gio.File.query_info() to get a list of attributes normally copied with the file (see Gio.File.copy_attributes() for the detailed description). This function is used by the implementation of Gio.File.copy_attributes() and is useful when one needs to query and set the attributes in two stages (e.g., for recursive move of a directory).

New in version 2.68.

copy(destination, flags, cancellable, progress_callback, *progress_callback_data)[source]
Parameters:
Raises:

GLib.Error

Returns:

True on success, False otherwise.

Return type:

bool

Copies the file self to the location specified by destination. Can not handle recursive copies of directories.

If the flag Gio.FileCopyFlags.OVERWRITE is specified an already existing destination file is overwritten.

If the flag Gio.FileCopyFlags.NOFOLLOW_SYMLINKS is specified then symlinks will be copied as symlinks, otherwise the target of the self symlink will be copied.

If the flag Gio.FileCopyFlags.ALL_METADATA is specified then all the metadata that is possible to copy is copied, not just the default subset (which, for instance, does not include the owner, see Gio.FileInfo).

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If progress_callback is not None, then the operation can be monitored by setting this to a Gio.FileProgressCallback function. progress_callback_data will be passed to this function. It is guaranteed that this callback will be called after all data has been transferred with the total number of bytes copied during the operation.

If the self file does not exist, then the Gio.IOErrorEnum.NOT_FOUND error is returned, independent on the status of the destination.

If Gio.FileCopyFlags.OVERWRITE is not specified and the target exists, then the error Gio.IOErrorEnum.EXISTS is returned.

If trying to overwrite a file over a directory, the Gio.IOErrorEnum.IS_DIRECTORY error is returned. If trying to overwrite a directory with a directory the Gio.IOErrorEnum.WOULD_MERGE error is returned.

If the source is a directory and the target does not exist, or Gio.FileCopyFlags.OVERWRITE is specified and the target is a file, then the Gio.IOErrorEnum.WOULD_RECURSE error is returned.

If you are interested in copying the Gio.File object itself (not the on-disk file), see Gio.File.dup().

copy_async(destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data)[source]
Parameters:

Copies the file self to the location specified by destination asynchronously. For details of the behaviour, see Gio.File.copy().

If progress_callback is not None, then that function that will be called just like in Gio.File.copy(). The callback will run in the default main context of the thread calling Gio.File.copy_async() — the same context as callback is run in.

When the operation is finished, callback will be called. You can then call Gio.File.copy_finish() to get the result of the operation.

copy_attributes(destination, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if the attributes were copied successfully, False otherwise.

Return type:

bool

Copies the file attributes from self 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 Gio.FileCopyFlags.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.

copy_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a True on success, False on error.

Return type:

bool

Finishes copying the file started with Gio.File.copy_async().

create(flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.FileOutputStream for the newly created file, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Creates a new file and returns an output stream for writing to it. The file must not already exist.

By default files created are generally readable by everyone, but if you pass Gio.FileCreateFlags.PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If a file or directory with this name already exists the Gio.IOErrorEnum.EXISTS error will be returned. Some file systems don’t allow all file names, and may return an Gio.IOErrorEnum.INVALID_FILENAME error, and if the name is to long Gio.IOErrorEnum.FILENAME_TOO_LONG will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

create_async(flags, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously creates a new file and returns an output stream for writing to it. The file must not already exist.

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

When the operation is finished, callback will be called. You can then call Gio.File.create_finish() to get the result of the operation.

create_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.FileOutputStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Finishes an asynchronous file create operation started with Gio.File.create_async().

create_readwrite(flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.FileIOStream for the newly created file, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Creates a new file and returns a stream for reading and writing to it. The file must not already exist.

By default files created are generally readable by everyone, but if you pass Gio.FileCreateFlags.PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If a file or directory with this name already exists, the Gio.IOErrorEnum.EXISTS error will be returned. Some file systems don’t allow all file names, and may return an Gio.IOErrorEnum.INVALID_FILENAME error, and if the name is too long, Gio.IOErrorEnum.FILENAME_TOO_LONG will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.

New in version 2.22.

create_readwrite_async(flags, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously creates a new file and returns a stream for reading and writing to it. The file must not already exist.

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

When the operation is finished, callback will be called. You can then call Gio.File.create_readwrite_finish() to get the result of the operation.

New in version 2.22.

create_readwrite_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.FileIOStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Finishes an asynchronous file create operation started with Gio.File.create_readwrite_async().

New in version 2.22.

delete(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Raises:

GLib.Error

Returns:

True if the file was deleted. False otherwise.

Return type:

bool

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

If self doesn’t exist, Gio.IOErrorEnum.NOT_FOUND will be returned. This allows for deletion to be implemented avoiding time-of-check to time-of-use races :

g_autoptr(GError) local_error = NULL;
if (!g_file_delete (my_file, my_cancellable, &local_error) &&
    !g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
  {
    // deletion failed for some reason other than the file not existing:
    // so report the error
    g_warning ("Failed to delete %s: %s",
               g_file_peek_path (my_file), local_error->message);
  }

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

delete_async(io_priority, cancellable, callback, *user_data)[source]
Parameters:

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

New in version 2.34.

delete_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the file was deleted. False otherwise.

Return type:

bool

Finishes deleting a file started with Gio.File.delete_async().

New in version 2.34.

dup()[source]
Returns:

a new Gio.File that is a duplicate of the given Gio.File.

Return type:

Gio.File

Duplicates a Gio.File handle. This operation does not duplicate the actual file or directory represented by the Gio.File; see Gio.File.copy() if attempting to copy a file.

Gio.File.dup() is useful when a second handle is needed to the same underlying file, for use in a separate thread (Gio.File is not thread-safe). For use within the same thread, use GObject.Object.ref() to increment the existing object’s reference count.

This call does no blocking I/O.

eject_mountable(flags, cancellable, callback, *user_data)[source]
Parameters:

Starts an asynchronous eject on a mountable. When this operation has completed, callback will be called with user_user data, and the operation can be finalized with Gio.File.eject_mountable_finish().

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

Deprecated since version 2.22: Use Gio.File.eject_mountable_with_operation() instead.

eject_mountable_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the self was ejected successfully. False otherwise.

Return type:

bool

Finishes an asynchronous eject operation started by Gio.File.eject_mountable().

Deprecated since version 2.22: Use Gio.File.eject_mountable_with_operation_finish() instead.

eject_mountable_with_operation(flags, mount_operation, cancellable, callback, *user_data)[source]
Parameters:

Starts an asynchronous eject on a mountable. When this operation has completed, callback will be called with user_user data, and the operation can be finalized with Gio.File.eject_mountable_with_operation_finish().

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

New in version 2.22.

eject_mountable_with_operation_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the self was ejected successfully. False otherwise.

Return type:

bool

Finishes an asynchronous eject operation started by Gio.File.eject_mountable_with_operation().

New in version 2.22.

enumerate_children(attributes, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

A Gio.FileEnumerator if successful, None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileEnumerator

Gets the requested information about the files in a directory. The result is a Gio.FileEnumerator object that will give out Gio.FileInfo objects for all the files in the directory.

The attributes value is a string that specifies the file attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “standard::*” means all attributes in the standard namespace. An example attribute query be “standard::*,owner::user”. The standard attributes are available as defines, like Gio.FILE_ATTRIBUTE_STANDARD_NAME. Gio.FILE_ATTRIBUTE_STANDARD_NAME should always be specified if you plan to call Gio.FileEnumerator.get_child() or Gio.FileEnumerator.iterate() on the returned enumerator.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If the file does not exist, the Gio.IOErrorEnum.NOT_FOUND error will be returned. If the file is not a directory, the Gio.IOErrorEnum.NOT_DIRECTORY error will be returned. Other errors are possible too.

enumerate_children_async(attributes, flags, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously gets the requested information about the files in a directory. The result is a Gio.FileEnumerator object that will give out Gio.FileInfo objects for all the files in the directory.

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

When the operation is finished, callback will be called. You can then call Gio.File.enumerate_children_finish() to get the result of the operation.

enumerate_children_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.FileEnumerator or None if an error occurred. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileEnumerator

Finishes an async enumerate children operation. See Gio.File.enumerate_children_async().

equal(file2)[source]
Parameters:

file2 (Gio.File) – the second Gio.File

Returns:

True if self and file2 are equal.

Return type:

bool

Checks if the two given Gio.Files refer to the same file.

Note that two Gio.Files that differ can still refer to the same file on the filesystem due to various forms of filename aliasing.

This call does no blocking I/O.

find_enclosing_mount(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Raises:

GLib.Error

Returns:

a Gio.Mount where the self is located or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.Mount

Gets a Gio.Mount for the Gio.File.

Gio.Mount is returned only for user interesting locations, see Gio.VolumeMonitor. If the Gio.FileIface for self does not have a #mount, error will be set to Gio.IOErrorEnum.NOT_FOUND and None #will be returned.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

find_enclosing_mount_async(io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously gets the mount for the file.

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

When the operation is finished, callback will be called. You can then call Gio.File.find_enclosing_mount_finish() to get the result of the operation.

find_enclosing_mount_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

Gio.Mount for given self or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.Mount

Finishes an asynchronous find mount request. See Gio.File.find_enclosing_mount_async().

get_basename()[source]
Returns:

string containing the Gio.File's base name, or None if given Gio.File is invalid. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str or None

Gets the base name (the last component of the path) for a given Gio.File.

If called for the top level of a system (such as the filesystem root or a uri like sftp://host/) 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 Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with Gio.File.query_info().

This call does no blocking I/O.

get_child(name)[source]
Parameters:

name (str) – string containing the child’s basename

Returns:

a Gio.File to a child specified by name. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Gets a child of self with basename equal to name.

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

This call does no blocking I/O.

get_child_for_display_name(display_name)[source]
Parameters:

display_name (str) – string to a possible child

Raises:

GLib.Error

Returns:

a Gio.File to the specified child, or None if the display name couldn’t be converted. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Gets the child of self for a given display_name (i.e. a UTF-8 version of the name). If this function fails, it returns None and error will be set. This is very useful when constructing a Gio.File for a new file and the user entered the filename in the user interface, for instance when you select a directory and type a filename in the file selector.

This call does no blocking I/O.

get_parent()[source]
Returns:

a Gio.File structure to the parent of the given Gio.File or None if there is no parent. Free the returned object with GObject.Object.unref().

Return type:

Gio.File or None

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

This call does no blocking I/O.

get_parse_name()[source]
Returns:

a string containing the Gio.File's parse name. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str

Gets the parse name of the self. A parse name is a UTF-8 string that describes the file such that one can get the Gio.File back using Gio.File.parse_name().

This is generally used to show the Gio.File 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.

get_path()[source]
Returns:

string containing the Gio.File's path, or None if no such path exists. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str or None

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

This call does no blocking I/O.

get_relative_path(descendant)[source]
Parameters:

descendant (Gio.File) – input Gio.File

Returns:

string with the relative path from descendant to self, or None if descendant doesn’t have self as prefix. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str or None

Gets the path for descendant relative to self.

This call does no blocking I/O.

get_uri()[source]
Returns:

a string containing the Gio.File's URI. If the Gio.File was constructed with an invalid URI, an invalid URI is returned. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str

Gets the URI for the self.

This call does no blocking I/O.

get_uri_scheme()[source]
Returns:

a string containing the URI scheme for the given Gio.File or None if the Gio.File was constructed with an invalid URI. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str or None

Gets the URI scheme for a Gio.File. RFC 3986 decodes the scheme as:

URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

Common schemes include “file”, “http”, “ftp”, etc.

The scheme can be different from the one used to construct the Gio.File, in that it might be replaced with one that is logically equivalent to the Gio.File.

This call does no blocking I/O.

has_parent(parent)[source]
Parameters:

parent (Gio.File or None) – the parent to check for, or None

Returns:

True if self is an immediate child of parent (or any parent in the case that parent is None).

Return type:

bool

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

If parent is None then this function returns True if self has any parent at all. If parent is non-None then True is only returned if self is an immediate child of parent.

New in version 2.24.

has_prefix(prefix)[source]
Parameters:

prefix (Gio.File) – input Gio.File

Returns:

True if the self's parent, grandparent, etc is prefix, False otherwise.

Return type:

bool

Checks whether self has the prefix specified by prefix.

In other words, if the names of initial elements of self'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 Gio.File is not a prefix of itself. If you want to check for equality, use Gio.File.equal().

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

has_uri_scheme(uri_scheme)[source]
Parameters:

uri_scheme (str) – a string containing a URI scheme

Returns:

True if Gio.File's backend supports the given URI scheme, False if URI scheme is None, not supported, or Gio.File is invalid.

Return type:

bool

Checks to see if a Gio.File has a given URI scheme.

This call does no blocking I/O.

hash()[source]
Returns:

0 if self is not a valid Gio.File, otherwise an integer that can be used as hash value for the Gio.File. This function is intended for easily hashing a Gio.File to add to a GLib.HashTable or similar data structure.

Return type:

int

Creates a hash value for a Gio.File.

This call does no blocking I/O.

is_native()[source]
Returns:

True if self is native

Return type:

bool

Checks to see if a file is native to the platform.

A native file is one expressed in the platform-native filename format, e.g. “C:\Windows” or “/usr/bin/”. This does not mean the file is local, as it might be on a locally mounted remote filesystem.

On some systems non-native files may be available using the native filesystem via a userspace filesystem (FUSE), in these cases this call will return False, but Gio.File.get_path() will still return a native path.

This call does no blocking I/O.

load_bytes(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – a Gio.Cancellable or None

Raises:

GLib.Error

Returns:

a GLib.Bytes or None and error is set

etag_out:

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

Return type:

(GLib.Bytes, etag_out: str or None)

Loads the contents of self and returns it as GLib.Bytes.

If self is a resource:// based URI, the resulting bytes will reference the embedded resource instead of a copy. Otherwise, this is equivalent to calling Gio.File.load_contents() and GLib.Bytes.new_take().

For resources, etag_out will be set to None.

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

New in version 2.56.

load_bytes_async(cancellable, callback, *user_data)[source]
Parameters:

Asynchronously loads the contents of self as GLib.Bytes.

If self is a resource:// based URI, the resulting bytes will reference the embedded resource instead of a copy. Otherwise, this is equivalent to calling Gio.File.load_contents_async() and GLib.Bytes.new_take().

callback should call Gio.File.load_bytes_finish() to get the result of this asynchronous operation.

See Gio.File.load_bytes() for more information.

New in version 2.56.

load_bytes_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult provided to the callback

Raises:

GLib.Error

Returns:

a GLib.Bytes or None and error is set

etag_out:

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

Return type:

(GLib.Bytes, etag_out: str or None)

Completes an asynchronous request to Gio.File.load_bytes_async().

For resources, etag_out will be set to None.

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

See Gio.File.load_bytes() for more information.

New in version 2.56.

load_contents(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Raises:

GLib.Error

Returns:

True if the self's contents were successfully loaded. False if there were errors.

contents:

a location to place the contents of the file

etag_out:

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

Return type:

(bool, contents: bytes, etag_out: str or None)

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 GLib.free() when no longer needed.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

load_contents_async(cancellable, callback, *user_data)[source]
Parameters:

Starts an asynchronous load of the self's contents.

For more details, see Gio.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 Gio.File.load_contents_finish() with the Gio.AsyncResult returned by the callback.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

load_contents_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

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

contents:

a location to place the contents of the file

etag_out:

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

Return type:

(bool, contents: bytes, etag_out: str or None)

Finishes an asynchronous load of the self'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 GLib.free() when no longer needed. If etag_out is present, it will be set to the new entity tag for the self.

load_partial_contents_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

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

contents:

a location to place the contents of the file

etag_out:

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

Return type:

(bool, contents: bytes, etag_out: str or None)

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 GLib.free() when no longer needed.

make_directory(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Raises:

GLib.Error

Returns:

True on successful creation, False otherwise.

Return type:

bool

Creates a directory. Note that this will only create a child directory of the immediate parent directory of the path or URI given by the Gio.File. To recursively create directories, see Gio.File.make_directory_with_parents(). This function will fail if the parent directory does not exist, setting error to Gio.IOErrorEnum.NOT_FOUND. If the file system doesn’t support creating directories, this function will fail, setting error to Gio.IOErrorEnum.NOT_SUPPORTED.

For a local Gio.File the newly created directory will have the default (current) ownership and permissions of the current process.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

make_directory_async(io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously creates a directory.

New in version 2.38.

make_directory_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True on successful directory creation, False otherwise.

Return type:

bool

Finishes an asynchronous directory creation, started with Gio.File.make_directory_async().

New in version 2.38.

make_directory_with_parents(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Raises:

GLib.Error

Returns:

True if all directories have been successfully created, False otherwise.

Return type:

bool

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 Gio.IOErrorEnum.NOT_SUPPORTED. If the directory itself already exists, this function will fail setting error to Gio.IOErrorEnum.EXISTS, unlike the similar GLib.mkdir_with_parents().

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

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

New in version 2.18.

Parameters:
Raises:

GLib.Error

Returns:

True on the creation of a new symlink, False otherwise.

Return type:

bool

Creates a symbolic link named self which contains the string symlink_value.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

Parameters:

Asynchronously creates a symbolic link named self which contains the string symlink_value.

New in version 2.74.

Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True on successful directory creation, False otherwise.

Return type:

bool

Finishes an asynchronous symbolic link creation, started with Gio.File.make_symbolic_link_async().

New in version 2.74.

measure_disk_usage(flags, cancellable, progress_callback, *progress_data)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if successful, with the out parameters set. False otherwise, with error set.

disk_usage:

the number of bytes of disk space used

num_dirs:

the number of directories encountered

num_files:

the number of non-directories encountered

Return type:

(bool, disk_usage: int, num_dirs: int, num_files: int)

Recursively measures the disk usage of self.

This is essentially an analog of the ‘du’ command, but it also reports the number of directories and non-directory files encountered (including things like symbolic links).

By default, errors are only reported against the toplevel file itself. Errors found while recursing are silently ignored, unless Gio.FileMeasureFlags.REPORT_ANY_ERROR is given in flags.

The returned size, disk_usage, is in bytes and should be formatted with GLib.format_size() in order to get something reasonable for showing in a user interface.

progress_callback and progress_data can be given to request periodic progress updates while scanning. See the documentation for Gio.FileMeasureProgressCallback for information about when and how the callback will be invoked.

New in version 2.38.

measure_disk_usage_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – the Gio.AsyncResult passed to your Gio.AsyncReadyCallback

Raises:

GLib.Error

Returns:

True if successful, with the out parameters set. False otherwise, with error set.

disk_usage:

the number of bytes of disk space used

num_dirs:

the number of directories encountered

num_files:

the number of non-directories encountered

Return type:

(bool, disk_usage: int, num_dirs: int, num_files: int)

Collects the results from an earlier call to g_file_measure_disk_usage_async(). See Gio.File.measure_disk_usage() for more information.

New in version 2.38.

monitor(flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.FileMonitor for the given self, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileMonitor

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

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

New in version 2.18.

monitor_directory(flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.FileMonitor for the given self, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileMonitor

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

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

It does not make sense for flags to contain Gio.FileMonitorFlags.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 Gio.File.monitor().

monitor_file(flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.FileMonitor for the given self, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileMonitor

Obtains a file monitor for the given file. If no file notification mechanism exists, then regular polling of the file is used.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If flags contains Gio.FileMonitorFlags.WATCH_HARD_LINKS then the monitor will also attempt to report changes made to the file via another filename (ie, a hard link). Without this flag, you can only rely on changes made through the filename contained in self to be reported. Using this flag may result in an increase in resource usage, and may not have any effect depending on the Gio.FileMonitor backend and/or filesystem type.

mount_enclosing_volume(flags, mount_operation, cancellable, callback, *user_data)[source]
Parameters:

Starts a mount_operation, mounting the volume that contains the file self.

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

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

mount_enclosing_volume_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

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

Return type:

bool

Finishes a mount operation started by Gio.File.mount_enclosing_volume().

mount_mountable(flags, mount_operation, cancellable, callback, *user_data)[source]
Parameters:

Mounts a file of type Gio.FileType.MOUNTABLE. Using mount_operation, you can request callbacks when, for instance, passwords are needed during authentication.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.mount_mountable_finish() to get the result of the operation.

mount_mountable_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.File or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Finishes a mount operation. See Gio.File.mount_mountable() for details.

Finish an asynchronous mount operation that was started with Gio.File.mount_mountable().

move(destination, flags, cancellable, progress_callback, *progress_callback_data)[source]
Parameters:
Raises:

GLib.Error

Returns:

True on successful move, False otherwise.

Return type:

bool

Tries to move the file or directory self to the location specified by destination. If native move operations are supported then this is used, otherwise a copy + delete fallback is used. The native implementation may support moving directories (for instance on moves inside the same filesystem), but the fallback code does not.

If the flag Gio.FileCopyFlags.OVERWRITE is specified an already existing destination file is overwritten.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If progress_callback is not None, then the operation can be monitored by setting this to a Gio.FileProgressCallback function. progress_callback_data will be passed to this function. It is guaranteed that this callback will be called after all data has been transferred with the total number of bytes copied during the operation.

If the self file does not exist, then the Gio.IOErrorEnum.NOT_FOUND error is returned, independent on the status of the destination.

If Gio.FileCopyFlags.OVERWRITE is not specified and the target exists, then the error Gio.IOErrorEnum.EXISTS is returned.

If trying to overwrite a file over a directory, the Gio.IOErrorEnum.IS_DIRECTORY error is returned. If trying to overwrite a directory with a directory the Gio.IOErrorEnum.WOULD_MERGE error is returned.

If the source is a directory and the target does not exist, or Gio.FileCopyFlags.OVERWRITE is specified and the target is a file, then the Gio.IOErrorEnum.WOULD_RECURSE error may be returned (if the native move operation isn’t available).

move_async(destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data)[source]
Parameters:

Asynchronously moves a file self to the location of destination. For details of the behaviour, see Gio.File.move().

If progress_callback is not None, then that function that will be called just like in Gio.File.move(). The callback will run in the default main context of the thread calling Gio.File.move_async() — the same context as callback is run in.

When the operation is finished, callback will be called. You can then call Gio.File.move_finish() to get the result of the operation.

New in version 2.72.

move_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True on successful file move, False otherwise.

Return type:

bool

Finishes an asynchronous file movement, started with Gio.File.move_async().

New in version 2.72.

open_readwrite(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – a Gio.Cancellable

Raises:

GLib.Error

Returns:

Gio.FileIOStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Opens an existing file for reading and writing. The result is a Gio.FileIOStream that can be used to read and write the contents of the file.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If the file does not exist, the Gio.IOErrorEnum.NOT_FOUND error will be returned. If the file is a directory, the Gio.IOErrorEnum.IS_DIRECTORY error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on. Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.

New in version 2.22.

open_readwrite_async(io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously opens self for reading and writing.

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

When the operation is finished, callback will be called. You can then call Gio.File.open_readwrite_finish() to get the result of the operation.

New in version 2.22.

open_readwrite_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.FileIOStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Finishes an asynchronous file read operation started with Gio.File.open_readwrite_async().

New in version 2.22.

peek_path()[source]
Returns:

string containing the Gio.File's path, or None if no such path exists. The returned string is owned by self.

Return type:

str or None

Exactly like Gio.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.

New in version 2.56.

poll_mountable(cancellable, callback, *user_data)[source]
Parameters:

Polls a file of type Gio.FileType.MOUNTABLE.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.mount_mountable_finish() to get the result of the operation.

New in version 2.22.

poll_mountable_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the operation finished successfully. False otherwise.

Return type:

bool

Finishes a poll operation. See Gio.File.poll_mountable() for details.

Finish an asynchronous poll operation that was polled with Gio.File.poll_mountable().

New in version 2.22.

query_default_handler(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Raises:

GLib.Error

Returns:

a Gio.AppInfo if the handle was found, None if there were errors. When you are done with it, release it with GObject.Object.unref()

Return type:

Gio.AppInfo

Returns the Gio.AppInfo that is registered as the default application to handle the file specified by self.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

query_default_handler_async(io_priority, cancellable, callback, *user_data)[source]
Parameters:

Async version of Gio.File.query_default_handler().

New in version 2.60.

query_default_handler_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.AppInfo if the handle was found, None if there were errors. When you are done with it, release it with GObject.Object.unref()

Return type:

Gio.AppInfo

Finishes a Gio.File.query_default_handler_async() operation.

New in version 2.60.

query_exists(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Returns:

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

Return type:

bool

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

Note that in many cases it is racy to first check for file existence 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 Gio.File.create() which will either atomically create the file or fail with a Gio.IOErrorEnum.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.

query_file_type(flags, cancellable)[source]
Parameters:
Returns:

The Gio.FileType of the file and Gio.FileType.UNKNOWN if the file does not exist

Return type:

Gio.FileType

Utility function to inspect the Gio.FileType of a file. This is implemented using Gio.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.

New in version 2.18.

query_filesystem_info(attributes, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.FileInfo or None if there was an error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInfo

Similar to Gio.File.query_info(), but obtains information about the filesystem the self is on, rather than the file itself. For instance the amount of space available and the type of the filesystem.

The attributes value is a string that specifies the attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “filesystem::*” means all attributes in the filesystem namespace. The standard namespace for filesystem attributes is “filesystem”. Common attributes of interest are Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE (the total size of the filesystem in bytes), Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE (number of bytes available), and Gio.FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If the file does not exist, the Gio.IOErrorEnum.NOT_FOUND error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

query_filesystem_info_async(attributes, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously gets the requested information about the filesystem that the specified self is on. The result is a Gio.FileInfo object that contains key-value attributes (such as type or size for the file).

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

When the operation is finished, callback will be called. You can then call Gio.File.query_info_finish() to get the result of the operation.

query_filesystem_info_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

Gio.FileInfo for given self or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInfo

Finishes an asynchronous filesystem info query. See Gio.File.query_filesystem_info_async().

query_info(attributes, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.FileInfo for the given self, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInfo

Gets the requested information about specified self. The result is a Gio.FileInfo object that contains key-value attributes (such as the type or size of the file).

The attributes value is a string that specifies the file attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “standard::*” means all attributes in the standard namespace. An example attribute query be “standard::*,owner::user”. The standard attributes are available as defines, like Gio.FILE_ATTRIBUTE_STANDARD_NAME.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

For symlinks, normally the information about the target of the symlink is returned, rather than information about the symlink itself. However if you pass Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS in flags the information about the symlink itself will be returned. Also, for symlinks that point to non-existing files the information about the symlink itself will be returned.

If the file does not exist, the Gio.IOErrorEnum.NOT_FOUND error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

query_info_async(attributes, flags, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously gets the requested information about specified self. The result is a Gio.FileInfo object that contains key-value attributes (such as type or size for the file).

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

When the operation is finished, callback will be called. You can then call Gio.File.query_info_finish() to get the result of the operation.

query_info_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

Gio.FileInfo for given self or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInfo

Finishes an asynchronous file info query. See Gio.File.query_info_async().

query_settable_attributes(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Raises:

GLib.Error

Returns:

a Gio.FileAttributeInfoList describing the settable attributes. When you are done with it, release it with Gio.FileAttributeInfoList.unref()

Return type:

Gio.FileAttributeInfoList

Obtain the list of settable attributes for the file.

Returns the type and full attribute name of all the attributes that can be set on this file. This doesn’t mean setting it will always succeed though, you might get an access failure, or some specific file may not support a specific attribute.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

query_writable_namespaces(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Raises:

GLib.Error

Returns:

a Gio.FileAttributeInfoList describing the writable namespaces. When you are done with it, release it with Gio.FileAttributeInfoList.unref()

Return type:

Gio.FileAttributeInfoList

Obtain the list of attribute namespaces where new attributes can be created by a user. An example of this is extended attributes (in the “xattr” namespace).

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

read(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – a Gio.Cancellable

Raises:

GLib.Error

Returns:

Gio.FileInputStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInputStream

Opens a file for reading. The result is a Gio.FileInputStream that can be used to read the contents of the file.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If the file does not exist, the Gio.IOErrorEnum.NOT_FOUND error will be returned. If the file is a directory, the Gio.IOErrorEnum.IS_DIRECTORY error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

read_async(io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously opens self for reading.

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

When the operation is finished, callback will be called. You can then call Gio.File.read_finish() to get the result of the operation.

read_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.FileInputStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInputStream

Finishes an asynchronous file read operation started with Gio.File.read_async().

replace(etag, make_backup, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.FileOutputStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Returns an output stream for overwriting the file, possibly creating a backup copy of the file first. If the file doesn’t exist, it will be created.

This will try to replace the file in the safest way possible so that any errors during the writing will not affect an already existing copy of the file. For instance, for local files it may write to a temporary file and then atomically rename over the destination when the stream is closed.

By default files created are generally readable by everyone, but if you pass Gio.FileCreateFlags.PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If you pass in a non-None etag value and self already exists, then this value is compared to the current entity tag of the file, and if they differ an Gio.IOErrorEnum.WRONG_ETAG error is returned. This generally means that the file has been changed since you last read it. You can get the new etag from Gio.FileOutputStream.get_etag() after you’ve finished writing and closed the Gio.FileOutputStream. When you load a new file you can use Gio.FileInputStream.query_info() to get the etag of the file.

If make_backup is True, this function will attempt to make a backup of the current file before overwriting it. If this fails a Gio.IOErrorEnum.CANT_CREATE_BACKUP error will be returned. If you want to replace anyway, try again with make_backup set to False.

If the file is a directory the Gio.IOErrorEnum.IS_DIRECTORY error will be returned, and if the file is some other form of non-regular file then a Gio.IOErrorEnum.NOT_REGULAR_FILE error will be returned. Some file systems don’t allow all file names, and may return an Gio.IOErrorEnum.INVALID_FILENAME error, and if the name is to long Gio.IOErrorEnum.FILENAME_TOO_LONG will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

replace_async(etag, make_backup, flags, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first.

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

When the operation is finished, callback will be called. You can then call Gio.File.replace_finish() to get the result of the operation.

replace_contents(contents, etag, make_backup, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

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

new_etag:

a location to a new entity tag for the document. This should be freed with GLib.free() when no longer needed, or None

Return type:

(bool, new_etag: str or None)

Replaces the contents of self with contents of length bytes.

If etag is specified (not None), any existing file must have that etag, or the error Gio.IOErrorEnum.WRONG_ETAG will be returned.

If make_backup is True, this function will attempt to make a backup of self. Internally, it uses Gio.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 None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.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.

replace_contents_async(contents, etag, make_backup, flags, cancellable, callback, *user_data)[source]
Parameters:

Starts an asynchronous replacement of self 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 Gio.File.replace_contents_finish().

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If make_backup is True, this function will attempt to make a backup of self.

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

replace_contents_bytes_async(contents, etag, make_backup, flags, cancellable, callback, *user_data)[source]
Parameters:

Same as Gio.File.replace_contents_async() but takes a GLib.Bytes input instead. This function will keep a ref on contents until the operation is done. Unlike Gio.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 Gio.File.replace_contents_finish().

New in version 2.40.

replace_contents_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True on success, False on failure.

new_etag:

a location of a new entity tag for the document. This should be freed with GLib.free() when it is no longer needed, or None

Return type:

(bool, new_etag: str or None)

Finishes an asynchronous replace of the given self. See Gio.File.replace_contents_async(). Sets new_etag to the new entity tag for the document, if present.

replace_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.FileOutputStream, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Finishes an asynchronous file replace operation started with Gio.File.replace_async().

replace_readwrite(etag, make_backup, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.FileIOStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Returns an output stream for overwriting the file in readwrite mode, possibly creating a backup copy of the file first. If the file doesn’t exist, it will be created.

For details about the behaviour, see Gio.File.replace() which does the same thing but returns an output stream only.

Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.

New in version 2.22.

replace_readwrite_async(etag, make_backup, flags, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously overwrites the file in read-write mode, replacing the contents, possibly creating a backup copy of the file first.

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

When the operation is finished, callback will be called. You can then call Gio.File.replace_readwrite_finish() to get the result of the operation.

New in version 2.22.

replace_readwrite_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.FileIOStream, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Finishes an asynchronous file replace operation started with Gio.File.replace_readwrite_async().

New in version 2.22.

resolve_relative_path(relative_path)[source]
Parameters:

relative_path (str) – a given relative path string

Returns:

a Gio.File for the resolved path.

Return type:

Gio.File

Resolves a relative path for self to an absolute path.

This call does no blocking I/O.

If the relative_path is an absolute path name, the resolution is done absolutely (without taking self path as base).

set_attribute(attribute, type, value_p, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if the attribute was set, False otherwise.

Return type:

bool

Sets an attribute in the file with attribute name attribute to value_p.

Some attributes can be unset by setting type to Gio.FileAttributeType.INVALID and value_p to None.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

set_attribute_byte_string(attribute, value, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if the attribute was successfully set to value in the self, False otherwise.

Return type:

bool

Sets attribute of type Gio.FileAttributeType.BYTE_STRING to value. If attribute is of a different type, this operation will fail, returning False.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

set_attribute_int32(attribute, value, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if the attribute was successfully set to value in the self, False otherwise.

Return type:

bool

Sets attribute of type Gio.FileAttributeType.INT32 to value. If attribute is of a different type, this operation will fail.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

set_attribute_int64(attribute, value, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if the attribute was successfully set, False otherwise.

Return type:

bool

Sets attribute of type Gio.FileAttributeType.INT64 to value. If attribute is of a different type, this operation will fail.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

set_attribute_string(attribute, value, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if the attribute was successfully set, False otherwise.

Return type:

bool

Sets attribute of type Gio.FileAttributeType.STRING to value. If attribute is of a different type, this operation will fail.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

set_attribute_uint32(attribute, value, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if the attribute was successfully set to value in the self, False otherwise.

Return type:

bool

Sets attribute of type Gio.FileAttributeType.UINT32 to value. If attribute is of a different type, this operation will fail.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

set_attribute_uint64(attribute, value, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

True if the attribute was successfully set to value in the self, False otherwise.

Return type:

bool

Sets attribute of type Gio.FileAttributeType.UINT64 to value. If attribute is of a different type, this operation will fail.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

set_attributes_async(info, flags, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously sets the attributes of self with info.

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

When the operation is finished, callback will be called. You can then call Gio.File.set_attributes_finish() to get the result of the operation.

set_attributes_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the attributes were set correctly, False otherwise.

info:

a Gio.FileInfo

Return type:

(bool, info: Gio.FileInfo)

Finishes setting an attribute started in Gio.File.set_attributes_async().

set_attributes_from_info(info, flags, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

False if there was any error, True otherwise.

Return type:

bool

Tries to set all attributes in the Gio.FileInfo on the target values, not stopping on the first error.

If there is any error during this operation then error will be set to the first error. Error on particular fields are flagged by setting the “status” field in the attribute value to Gio.FileAttributeStatus.ERROR_SETTING, which means you can also detect further errors.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

set_display_name(display_name, cancellable)[source]
Parameters:
Raises:

GLib.Error

Returns:

a Gio.File specifying what self was renamed to, or None if there was an error. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Renames self to the specified display name.

The display name is converted from UTF-8 to the correct encoding for the target filesystem if possible and the self is renamed to this.

If you want to implement a rename operation in the user interface the edit name (Gio.FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the initial value in the rename widget, and then the result after editing should be passed to Gio.File.set_display_name().

On success the resulting converted filename is returned.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

set_display_name_async(display_name, io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously sets the display name for a given Gio.File.

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

When the operation is finished, callback will be called. You can then call Gio.File.set_display_name_finish() to get the result of the operation.

set_display_name_finish(res)[source]
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.File or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Finishes setting a display name started with Gio.File.set_display_name_async().

start_mountable(flags, start_operation, cancellable, callback, *user_data)[source]
Parameters:

Starts a file of type Gio.FileType.MOUNTABLE. Using start_operation, you can request callbacks when, for instance, passwords are needed during authentication.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.mount_mountable_finish() to get the result of the operation.

New in version 2.22.

start_mountable_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the operation finished successfully. False otherwise.

Return type:

bool

Finishes a start operation. See Gio.File.start_mountable() for details.

Finish an asynchronous start operation that was started with Gio.File.start_mountable().

New in version 2.22.

stop_mountable(flags, mount_operation, cancellable, callback, *user_data)[source]
Parameters:

Stops a file of type Gio.FileType.MOUNTABLE.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.stop_mountable_finish() to get the result of the operation.

New in version 2.22.

stop_mountable_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the operation finished successfully. False otherwise.

Return type:

bool

Finishes a stop operation, see Gio.File.stop_mountable() for details.

Finish an asynchronous stop operation that was started with Gio.File.stop_mountable().

New in version 2.22.

supports_thread_contexts()[source]
Returns:

Whether or not self supports thread-default contexts.

Return type:

bool

Checks if self supports ‘thread-default contexts [g-main-context-push-thread-default-context]’. If this returns False, you cannot perform asynchronous operations on self in a thread that has a thread-default context.

New in version 2.22.

trash(cancellable)[source]
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Raises:

GLib.Error

Returns:

True on successful trash, False otherwise.

Return type:

bool

Sends self to the “Trashcan”, if possible. This is similar to deleting it, but the user can recover it before emptying the trashcan. Not all file systems support trashing, so this call can return the Gio.IOErrorEnum.NOT_SUPPORTED error. Since GLib 2.66, the x-gvfs-notrash unix mount option can be used to disable Gio.File.trash() support for certain mounts, the Gio.IOErrorEnum.NOT_SUPPORTED error will be returned in that case.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

trash_async(io_priority, cancellable, callback, *user_data)[source]
Parameters:

Asynchronously sends self to the Trash location, if possible.

New in version 2.38.

trash_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True on successful trash, False otherwise.

Return type:

bool

Finishes an asynchronous file trashing operation, started with Gio.File.trash_async().

New in version 2.38.

unmount_mountable(flags, cancellable, callback, *user_data)[source]
Parameters:

Unmounts a file of type Gio.FileType.MOUNTABLE.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.unmount_mountable_finish() to get the result of the operation.

Deprecated since version 2.22: Use Gio.File.unmount_mountable_with_operation() instead.

unmount_mountable_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the operation finished successfully. False otherwise.

Return type:

bool

Finishes an unmount operation, see Gio.File.unmount_mountable() for details.

Finish an asynchronous unmount operation that was started with Gio.File.unmount_mountable().

Deprecated since version 2.22: Use Gio.File.unmount_mountable_with_operation_finish() instead.

unmount_mountable_with_operation(flags, mount_operation, cancellable, callback, *user_data)[source]
Parameters:

Unmounts a file of type Gio.FileType.MOUNTABLE.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.unmount_mountable_finish() to get the result of the operation.

New in version 2.22.

unmount_mountable_with_operation_finish(result)[source]
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the operation finished successfully. False otherwise.

Return type:

bool

Finishes an unmount operation, see Gio.File.unmount_mountable_with_operation() for details.

Finish an asynchronous unmount operation that was started with Gio.File.unmount_mountable_with_operation().

New in version 2.22.

do_append_to(flags, cancellable) virtual
Parameters:
Returns:

a Gio.FileOutputStream, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Gets an output stream for appending data to the file. If the file doesn’t already exist it is created.

By default files created are generally readable by everyone, but if you pass Gio.FileCreateFlags.PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

Some file systems don’t allow all file names, and may return an Gio.IOErrorEnum.INVALID_FILENAME error. If the file is a directory the Gio.IOErrorEnum.IS_DIRECTORY error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

do_append_to_async(flags, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously opens file for appending.

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

When the operation is finished, callback will be called. You can then call Gio.File.append_to_finish() to get the result of the operation.

do_append_to_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – Gio.AsyncResult

Returns:

a valid Gio.FileOutputStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Finishes an asynchronous file append operation started with Gio.File.append_to_async().

do_copy(destination, flags, cancellable, progress_callback, progress_callback_data) virtual
Parameters:
Returns:

True on success, False otherwise.

Return type:

bool

Copies the file source to the location specified by destination. Can not handle recursive copies of directories.

If the flag Gio.FileCopyFlags.OVERWRITE is specified an already existing destination file is overwritten.

If the flag Gio.FileCopyFlags.NOFOLLOW_SYMLINKS is specified then symlinks will be copied as symlinks, otherwise the target of the source symlink will be copied.

If the flag Gio.FileCopyFlags.ALL_METADATA is specified then all the metadata that is possible to copy is copied, not just the default subset (which, for instance, does not include the owner, see Gio.FileInfo).

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If progress_callback is not None, then the operation can be monitored by setting this to a Gio.FileProgressCallback function. progress_callback_data will be passed to this function. It is guaranteed that this callback will be called after all data has been transferred with the total number of bytes copied during the operation.

If the source file does not exist, then the Gio.IOErrorEnum.NOT_FOUND error is returned, independent on the status of the destination.

If Gio.FileCopyFlags.OVERWRITE is not specified and the target exists, then the error Gio.IOErrorEnum.EXISTS is returned.

If trying to overwrite a file over a directory, the Gio.IOErrorEnum.IS_DIRECTORY error is returned. If trying to overwrite a directory with a directory the Gio.IOErrorEnum.WOULD_MERGE error is returned.

If the source is a directory and the target does not exist, or Gio.FileCopyFlags.OVERWRITE is specified and the target is a file, then the Gio.IOErrorEnum.WOULD_RECURSE error is returned.

If you are interested in copying the Gio.File object itself (not the on-disk file), see Gio.File.dup().

do_copy_async(destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data) virtual
Parameters:

Copies the file source to the location specified by destination asynchronously. For details of the behaviour, see Gio.File.copy().

If progress_callback is not None, then that function that will be called just like in Gio.File.copy(). The callback will run in the default main context of the thread calling Gio.File.copy_async() — the same context as callback is run in.

When the operation is finished, callback will be called. You can then call Gio.File.copy_finish() to get the result of the operation.

do_copy_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a True on success, False on error.

Return type:

bool

Finishes copying the file started with Gio.File.copy_async().

do_create(flags, cancellable) virtual
Parameters:
Returns:

a Gio.FileOutputStream for the newly created file, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Creates a new file and returns an output stream for writing to it. The file must not already exist.

By default files created are generally readable by everyone, but if you pass Gio.FileCreateFlags.PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If a file or directory with this name already exists the Gio.IOErrorEnum.EXISTS error will be returned. Some file systems don’t allow all file names, and may return an Gio.IOErrorEnum.INVALID_FILENAME error, and if the name is to long Gio.IOErrorEnum.FILENAME_TOO_LONG will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

do_create_async(flags, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously creates a new file and returns an output stream for writing to it. The file must not already exist.

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

When the operation is finished, callback will be called. You can then call Gio.File.create_finish() to get the result of the operation.

do_create_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a Gio.FileOutputStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Finishes an asynchronous file create operation started with Gio.File.create_async().

do_create_readwrite(flags, cancellable) virtual
Parameters:
Returns:

a Gio.FileIOStream for the newly created file, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Creates a new file and returns a stream for reading and writing to it. The file must not already exist.

By default files created are generally readable by everyone, but if you pass Gio.FileCreateFlags.PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If a file or directory with this name already exists, the Gio.IOErrorEnum.EXISTS error will be returned. Some file systems don’t allow all file names, and may return an Gio.IOErrorEnum.INVALID_FILENAME error, and if the name is too long, Gio.IOErrorEnum.FILENAME_TOO_LONG will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.

New in version 2.22.

do_create_readwrite_async(flags, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously creates a new file and returns a stream for reading and writing to it. The file must not already exist.

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

When the operation is finished, callback will be called. You can then call Gio.File.create_readwrite_finish() to get the result of the operation.

New in version 2.22.

do_create_readwrite_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a Gio.FileIOStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Finishes an asynchronous file create operation started with Gio.File.create_readwrite_async().

New in version 2.22.

do_delete_file(cancellable) virtual
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Returns:

True if the file was deleted. False otherwise.

Return type:

bool

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

If file doesn’t exist, Gio.IOErrorEnum.NOT_FOUND will be returned. This allows for deletion to be implemented avoiding time-of-check to time-of-use races :

g_autoptr(GError) local_error = NULL;
if (!g_file_delete (my_file, my_cancellable, &local_error) &&
    !g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
  {
    // deletion failed for some reason other than the file not existing:
    // so report the error
    g_warning ("Failed to delete %s: %s",
               g_file_peek_path (my_file), local_error->message);
  }

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

do_delete_file_async(io_priority, cancellable, callback, *user_data) virtual
Parameters:

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 GLib.unlink().

New in version 2.34.

do_delete_file_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True if the file was deleted. False otherwise.

Return type:

bool

Finishes deleting a file started with Gio.File.delete_async().

New in version 2.34.

do_dup() virtual
Returns:

a new Gio.File that is a duplicate of the given Gio.File.

Return type:

Gio.File

Duplicates a Gio.File handle. This operation does not duplicate the actual file or directory represented by the Gio.File; see Gio.File.copy() if attempting to copy a file.

Gio.File.dup() is useful when a second handle is needed to the same underlying file, for use in a separate thread (Gio.File is not thread-safe). For use within the same thread, use GObject.Object.ref() to increment the existing object’s reference count.

This call does no blocking I/O.

do_eject_mountable(flags, cancellable, callback, *user_data) virtual
Parameters:

Starts an asynchronous eject on a mountable. When this operation has completed, callback will be called with user_user data, and the operation can be finalized with Gio.File.eject_mountable_finish().

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

Deprecated since version 2.22: Use Gio.File.eject_mountable_with_operation() instead.

do_eject_mountable_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True if the file was ejected successfully. False otherwise.

Return type:

bool

Finishes an asynchronous eject operation started by Gio.File.eject_mountable().

Deprecated since version 2.22: Use Gio.File.eject_mountable_with_operation_finish() instead.

do_eject_mountable_with_operation(flags, mount_operation, cancellable, callback, *user_data) virtual
Parameters:

Starts an asynchronous eject on a mountable. When this operation has completed, callback will be called with user_user data, and the operation can be finalized with Gio.File.eject_mountable_with_operation_finish().

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

New in version 2.22.

do_eject_mountable_with_operation_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True if the file was ejected successfully. False otherwise.

Return type:

bool

Finishes an asynchronous eject operation started by Gio.File.eject_mountable_with_operation().

New in version 2.22.

do_enumerate_children(attributes, flags, cancellable) virtual
Parameters:
Returns:

A Gio.FileEnumerator if successful, None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileEnumerator

Gets the requested information about the files in a directory. The result is a Gio.FileEnumerator object that will give out Gio.FileInfo objects for all the files in the directory.

The attributes value is a string that specifies the file attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “standard::*” means all attributes in the standard namespace. An example attribute query be “standard::*,owner::user”. The standard attributes are available as defines, like Gio.FILE_ATTRIBUTE_STANDARD_NAME. Gio.FILE_ATTRIBUTE_STANDARD_NAME should always be specified if you plan to call Gio.FileEnumerator.get_child() or Gio.FileEnumerator.iterate() on the returned enumerator.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If the file does not exist, the Gio.IOErrorEnum.NOT_FOUND error will be returned. If the file is not a directory, the Gio.IOErrorEnum.NOT_DIRECTORY error will be returned. Other errors are possible too.

do_enumerate_children_async(attributes, flags, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously gets the requested information about the files in a directory. The result is a Gio.FileEnumerator object that will give out Gio.FileInfo objects for all the files in the directory.

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

When the operation is finished, callback will be called. You can then call Gio.File.enumerate_children_finish() to get the result of the operation.

do_enumerate_children_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a Gio.FileEnumerator or None if an error occurred. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileEnumerator

Finishes an async enumerate children operation. See Gio.File.enumerate_children_async().

do_equal(file2) virtual
Parameters:

file2 (Gio.File) – the second Gio.File

Returns:

True if file1 and file2 are equal.

Return type:

bool

Checks if the two given Gio.Files refer to the same file.

Note that two Gio.Files that differ can still refer to the same file on the filesystem due to various forms of filename aliasing.

This call does no blocking I/O.

do_find_enclosing_mount(cancellable) virtual
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Returns:

a Gio.Mount where the file is located or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.Mount

Gets a Gio.Mount for the Gio.File.

Gio.Mount is returned only for user interesting locations, see Gio.VolumeMonitor. If the Gio.FileIface for file does not have a #mount, error will be set to Gio.IOErrorEnum.NOT_FOUND and None #will be returned.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

do_find_enclosing_mount_async(io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously gets the mount for the file.

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

When the operation is finished, callback will be called. You can then call Gio.File.find_enclosing_mount_finish() to get the result of the operation.

do_find_enclosing_mount_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

Gio.Mount for given file or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.Mount

Finishes an asynchronous find mount request. See Gio.File.find_enclosing_mount_async().

do_get_basename() virtual
Returns:

string containing the Gio.File's base name, or None if given Gio.File is invalid. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str or None

Gets the base name (the last component of the path) for a given Gio.File.

If called for the top level of a system (such as the filesystem root or a uri like sftp://host/) 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 Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with Gio.File.query_info().

This call does no blocking I/O.

do_get_child_for_display_name(display_name) virtual
Parameters:

display_name (str) – string to a possible child

Returns:

a Gio.File to the specified child, or None if the display name couldn’t be converted. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Gets the child of file for a given display_name (i.e. a UTF-8 version of the name). If this function fails, it returns None and error will be set. This is very useful when constructing a Gio.File for a new file and the user entered the filename in the user interface, for instance when you select a directory and type a filename in the file selector.

This call does no blocking I/O.

do_get_parent() virtual
Returns:

a Gio.File structure to the parent of the given Gio.File or None if there is no parent. Free the returned object with GObject.Object.unref().

Return type:

Gio.File or None

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

This call does no blocking I/O.

do_get_parse_name() virtual
Returns:

a string containing the Gio.File's parse name. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str

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 Gio.File back using Gio.File.parse_name().

This is generally used to show the Gio.File 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.

do_get_path() virtual
Returns:

string containing the Gio.File's path, or None if no such path exists. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str or None

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

This call does no blocking I/O.

do_get_relative_path(descendant) virtual
Parameters:

descendant (Gio.File) – input Gio.File

Returns:

string with the relative path from descendant to parent, or None if descendant doesn’t have parent as prefix. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str or None

Gets the path for descendant relative to parent.

This call does no blocking I/O.

do_get_uri() virtual
Returns:

a string containing the Gio.File's URI. If the Gio.File was constructed with an invalid URI, an invalid URI is returned. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str

Gets the URI for the file.

This call does no blocking I/O.

do_get_uri_scheme() virtual
Returns:

a string containing the URI scheme for the given Gio.File or None if the Gio.File was constructed with an invalid URI. The returned string should be freed with GLib.free() when no longer needed.

Return type:

str or None

Gets the URI scheme for a Gio.File. RFC 3986 decodes the scheme as:

URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

Common schemes include “file”, “http”, “ftp”, etc.

The scheme can be different from the one used to construct the Gio.File, in that it might be replaced with one that is logically equivalent to the Gio.File.

This call does no blocking I/O.

do_has_uri_scheme(uri_scheme) virtual
Parameters:

uri_scheme (str) – a string containing a URI scheme

Returns:

True if Gio.File's backend supports the given URI scheme, False if URI scheme is None, not supported, or Gio.File is invalid.

Return type:

bool

Checks to see if a Gio.File has a given URI scheme.

This call does no blocking I/O.

do_hash() virtual
Returns:

0 if file is not a valid Gio.File, otherwise an integer that can be used as hash value for the Gio.File. This function is intended for easily hashing a Gio.File to add to a GLib.HashTable or similar data structure.

Return type:

int

Creates a hash value for a Gio.File.

This call does no blocking I/O.

do_is_native() virtual
Returns:

True if file is native

Return type:

bool

Checks to see if a file is native to the platform.

A native file is one expressed in the platform-native filename format, e.g. “C:\Windows” or “/usr/bin/”. This does not mean the file is local, as it might be on a locally mounted remote filesystem.

On some systems non-native files may be available using the native filesystem via a userspace filesystem (FUSE), in these cases this call will return False, but Gio.File.get_path() will still return a native path.

This call does no blocking I/O.

do_make_directory(cancellable) virtual
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Returns:

True on successful creation, False otherwise.

Return type:

bool

Creates a directory. Note that this will only create a child directory of the immediate parent directory of the path or URI given by the Gio.File. To recursively create directories, see Gio.File.make_directory_with_parents(). This function will fail if the parent directory does not exist, setting error to Gio.IOErrorEnum.NOT_FOUND. If the file system doesn’t support creating directories, this function will fail, setting error to Gio.IOErrorEnum.NOT_SUPPORTED.

For a local Gio.File the newly created directory will have the default (current) ownership and permissions of the current process.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

do_make_directory_async(io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously creates a directory.

New in version 2.38.

do_make_directory_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True on successful directory creation, False otherwise.

Return type:

bool

Finishes an asynchronous directory creation, started with Gio.File.make_directory_async().

New in version 2.38.

Parameters:
Returns:

True on the creation of a new symlink, False otherwise.

Return type:

bool

Creates a symbolic link named file which contains the string symlink_value.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

Parameters:

Asynchronously creates a symbolic link named file which contains the string symlink_value.

New in version 2.74.

Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True on successful directory creation, False otherwise.

Return type:

bool

Finishes an asynchronous symbolic link creation, started with Gio.File.make_symbolic_link_async().

New in version 2.74.

do_measure_disk_usage(flags, cancellable, progress_callback, progress_data) virtual
Parameters:
Returns:

True if successful, with the out parameters set. False otherwise, with error set.

disk_usage:

the number of bytes of disk space used

num_dirs:

the number of directories encountered

num_files:

the number of non-directories encountered

Return type:

(bool, disk_usage: int, num_dirs: int, num_files: int)

Recursively measures the disk usage of file.

This is essentially an analog of the ‘du’ command, but it also reports the number of directories and non-directory files encountered (including things like symbolic links).

By default, errors are only reported against the toplevel file itself. Errors found while recursing are silently ignored, unless Gio.FileMeasureFlags.REPORT_ANY_ERROR is given in flags.

The returned size, disk_usage, is in bytes and should be formatted with GLib.format_size() in order to get something reasonable for showing in a user interface.

progress_callback and progress_data can be given to request periodic progress updates while scanning. See the documentation for Gio.FileMeasureProgressCallback for information about when and how the callback will be invoked.

New in version 2.38.

do_measure_disk_usage_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – the Gio.AsyncResult passed to your Gio.AsyncReadyCallback

Returns:

True if successful, with the out parameters set. False otherwise, with error set.

disk_usage:

the number of bytes of disk space used

num_dirs:

the number of directories encountered

num_files:

the number of non-directories encountered

Return type:

(bool, disk_usage: int, num_dirs: int, num_files: int)

Collects the results from an earlier call to g_file_measure_disk_usage_async(). See Gio.File.measure_disk_usage() for more information.

New in version 2.38.

do_monitor_dir(flags, cancellable) virtual
Parameters:
Returns:

a Gio.FileMonitor for the given file, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileMonitor

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

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

It does not make sense for flags to contain Gio.FileMonitorFlags.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 Gio.File.monitor().

do_monitor_file(flags, cancellable) virtual
Parameters:
Returns:

a Gio.FileMonitor for the given file, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileMonitor

Obtains a file monitor for the given file. If no file notification mechanism exists, then regular polling of the file is used.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If flags contains Gio.FileMonitorFlags.WATCH_HARD_LINKS then the monitor will also attempt to report changes made to the file via another filename (ie, a hard link). Without this flag, you can only rely on changes made through the filename contained in file to be reported. Using this flag may result in an increase in resource usage, and may not have any effect depending on the Gio.FileMonitor backend and/or filesystem type.

do_mount_enclosing_volume(flags, mount_operation, cancellable, callback, *user_data) virtual
Parameters:

Starts a mount_operation, mounting the volume that contains the file location.

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

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

do_mount_enclosing_volume_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

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

Return type:

bool

Finishes a mount operation started by Gio.File.mount_enclosing_volume().

do_mount_mountable(flags, mount_operation, cancellable, callback, *user_data) virtual
Parameters:

Mounts a file of type Gio.FileType.MOUNTABLE. Using mount_operation, you can request callbacks when, for instance, passwords are needed during authentication.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.mount_mountable_finish() to get the result of the operation.

do_mount_mountable_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a Gio.File or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Finishes a mount operation. See Gio.File.mount_mountable() for details.

Finish an asynchronous mount operation that was started with Gio.File.mount_mountable().

do_move(destination, flags, cancellable, progress_callback, progress_callback_data) virtual
Parameters:
Returns:

True on successful move, False otherwise.

Return type:

bool

Tries to move the file or directory source to the location specified by destination. If native move operations are supported then this is used, otherwise a copy + delete fallback is used. The native implementation may support moving directories (for instance on moves inside the same filesystem), but the fallback code does not.

If the flag Gio.FileCopyFlags.OVERWRITE is specified an already existing destination file is overwritten.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If progress_callback is not None, then the operation can be monitored by setting this to a Gio.FileProgressCallback function. progress_callback_data will be passed to this function. It is guaranteed that this callback will be called after all data has been transferred with the total number of bytes copied during the operation.

If the source file does not exist, then the Gio.IOErrorEnum.NOT_FOUND error is returned, independent on the status of the destination.

If Gio.FileCopyFlags.OVERWRITE is not specified and the target exists, then the error Gio.IOErrorEnum.EXISTS is returned.

If trying to overwrite a file over a directory, the Gio.IOErrorEnum.IS_DIRECTORY error is returned. If trying to overwrite a directory with a directory the Gio.IOErrorEnum.WOULD_MERGE error is returned.

If the source is a directory and the target does not exist, or Gio.FileCopyFlags.OVERWRITE is specified and the target is a file, then the Gio.IOErrorEnum.WOULD_RECURSE error may be returned (if the native move operation isn’t available).

do_move_async(destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data) virtual
Parameters:

Asynchronously moves a file source to the location of destination. For details of the behaviour, see Gio.File.move().

If progress_callback is not None, then that function that will be called just like in Gio.File.move(). The callback will run in the default main context of the thread calling Gio.File.move_async() — the same context as callback is run in.

When the operation is finished, callback will be called. You can then call Gio.File.move_finish() to get the result of the operation.

New in version 2.72.

do_move_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True on successful file move, False otherwise.

Return type:

bool

Finishes an asynchronous file movement, started with Gio.File.move_async().

New in version 2.72.

do_open_readwrite(cancellable) virtual
Parameters:

cancellable (Gio.Cancellable or None) – a Gio.Cancellable

Returns:

Gio.FileIOStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Opens an existing file for reading and writing. The result is a Gio.FileIOStream that can be used to read and write the contents of the file.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If the file does not exist, the Gio.IOErrorEnum.NOT_FOUND error will be returned. If the file is a directory, the Gio.IOErrorEnum.IS_DIRECTORY error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on. Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.

New in version 2.22.

do_open_readwrite_async(io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously opens file for reading and writing.

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

When the operation is finished, callback will be called. You can then call Gio.File.open_readwrite_finish() to get the result of the operation.

New in version 2.22.

do_open_readwrite_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a Gio.FileIOStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Finishes an asynchronous file read operation started with Gio.File.open_readwrite_async().

New in version 2.22.

do_poll_mountable(cancellable, callback, *user_data) virtual
Parameters:

Polls a file of type Gio.FileType.MOUNTABLE.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.mount_mountable_finish() to get the result of the operation.

New in version 2.22.

do_poll_mountable_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True if the operation finished successfully. False otherwise.

Return type:

bool

Finishes a poll operation. See Gio.File.poll_mountable() for details.

Finish an asynchronous poll operation that was polled with Gio.File.poll_mountable().

New in version 2.22.

do_prefix_matches(file) virtual
Parameters:

file (Gio.File) – input Gio.File

Returns:

True if the file's parent, grandparent, etc is prefix, False otherwise.

Return type:

bool

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 Gio.File is not a prefix of itself. If you want to check for equality, use Gio.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.

do_query_filesystem_info(attributes, cancellable) virtual
Parameters:
Returns:

a Gio.FileInfo or None if there was an error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInfo

Similar to Gio.File.query_info(), but obtains information about the filesystem the file is on, rather than the file itself. For instance the amount of space available and the type of the filesystem.

The attributes value is a string that specifies the attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “filesystem::*” means all attributes in the filesystem namespace. The standard namespace for filesystem attributes is “filesystem”. Common attributes of interest are Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE (the total size of the filesystem in bytes), Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE (number of bytes available), and Gio.FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If the file does not exist, the Gio.IOErrorEnum.NOT_FOUND error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

do_query_filesystem_info_async(attributes, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously gets the requested information about the filesystem that the specified file is on. The result is a Gio.FileInfo object that contains key-value attributes (such as type or size for the file).

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

When the operation is finished, callback will be called. You can then call Gio.File.query_info_finish() to get the result of the operation.

do_query_filesystem_info_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

Gio.FileInfo for given file or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInfo

Finishes an asynchronous filesystem info query. See Gio.File.query_filesystem_info_async().

do_query_info(attributes, flags, cancellable) virtual
Parameters:
Returns:

a Gio.FileInfo for the given file, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInfo

Gets the requested information about specified file. The result is a Gio.FileInfo object that contains key-value attributes (such as the type or size of the file).

The attributes value is a string that specifies the file attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “standard::*” means all attributes in the standard namespace. An example attribute query be “standard::*,owner::user”. The standard attributes are available as defines, like Gio.FILE_ATTRIBUTE_STANDARD_NAME.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

For symlinks, normally the information about the target of the symlink is returned, rather than information about the symlink itself. However if you pass Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS in flags the information about the symlink itself will be returned. Also, for symlinks that point to non-existing files the information about the symlink itself will be returned.

If the file does not exist, the Gio.IOErrorEnum.NOT_FOUND error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

do_query_info_async(attributes, flags, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously gets the requested information about specified file. The result is a Gio.FileInfo object that contains key-value attributes (such as type or size for the file).

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

When the operation is finished, callback will be called. You can then call Gio.File.query_info_finish() to get the result of the operation.

do_query_info_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

Gio.FileInfo for given file or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInfo

Finishes an asynchronous file info query. See Gio.File.query_info_async().

do_query_settable_attributes(cancellable) virtual
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Returns:

a Gio.FileAttributeInfoList describing the settable attributes. When you are done with it, release it with Gio.FileAttributeInfoList.unref()

Return type:

Gio.FileAttributeInfoList

Obtain the list of settable attributes for the file.

Returns the type and full attribute name of all the attributes that can be set on this file. This doesn’t mean setting it will always succeed though, you might get an access failure, or some specific file may not support a specific attribute.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

do_query_writable_namespaces(cancellable) virtual
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Returns:

a Gio.FileAttributeInfoList describing the writable namespaces. When you are done with it, release it with Gio.FileAttributeInfoList.unref()

Return type:

Gio.FileAttributeInfoList

Obtain the list of attribute namespaces where new attributes can be created by a user. An example of this is extended attributes (in the “xattr” namespace).

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

do_read_async(io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously opens file for reading.

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

When the operation is finished, callback will be called. You can then call Gio.File.read_finish() to get the result of the operation.

do_read_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a Gio.FileInputStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInputStream

Finishes an asynchronous file read operation started with Gio.File.read_async().

do_read_fn(cancellable) virtual
Parameters:

cancellable (Gio.Cancellable or None) – a Gio.Cancellable

Returns:

Gio.FileInputStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileInputStream

Opens a file for reading. The result is a Gio.FileInputStream that can be used to read the contents of the file.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If the file does not exist, the Gio.IOErrorEnum.NOT_FOUND error will be returned. If the file is a directory, the Gio.IOErrorEnum.IS_DIRECTORY error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

do_replace(etag, make_backup, flags, cancellable) virtual
Parameters:
Returns:

a Gio.FileOutputStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Returns an output stream for overwriting the file, possibly creating a backup copy of the file first. If the file doesn’t exist, it will be created.

This will try to replace the file in the safest way possible so that any errors during the writing will not affect an already existing copy of the file. For instance, for local files it may write to a temporary file and then atomically rename over the destination when the stream is closed.

By default files created are generally readable by everyone, but if you pass Gio.FileCreateFlags.PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

If you pass in a non-None etag value and file already exists, then this value is compared to the current entity tag of the file, and if they differ an Gio.IOErrorEnum.WRONG_ETAG error is returned. This generally means that the file has been changed since you last read it. You can get the new etag from Gio.FileOutputStream.get_etag() after you’ve finished writing and closed the Gio.FileOutputStream. When you load a new file you can use Gio.FileInputStream.query_info() to get the etag of the file.

If make_backup is True, this function will attempt to make a backup of the current file before overwriting it. If this fails a Gio.IOErrorEnum.CANT_CREATE_BACKUP error will be returned. If you want to replace anyway, try again with make_backup set to False.

If the file is a directory the Gio.IOErrorEnum.IS_DIRECTORY error will be returned, and if the file is some other form of non-regular file then a Gio.IOErrorEnum.NOT_REGULAR_FILE error will be returned. Some file systems don’t allow all file names, and may return an Gio.IOErrorEnum.INVALID_FILENAME error, and if the name is to long Gio.IOErrorEnum.FILENAME_TOO_LONG will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

do_replace_async(etag, make_backup, flags, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first.

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

When the operation is finished, callback will be called. You can then call Gio.File.replace_finish() to get the result of the operation.

do_replace_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a Gio.FileOutputStream, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileOutputStream

Finishes an asynchronous file replace operation started with Gio.File.replace_async().

do_replace_readwrite(etag, make_backup, flags, cancellable) virtual
Parameters:
Returns:

a Gio.FileIOStream or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Returns an output stream for overwriting the file in readwrite mode, possibly creating a backup copy of the file first. If the file doesn’t exist, it will be created.

For details about the behaviour, see Gio.File.replace() which does the same thing but returns an output stream only.

Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.

New in version 2.22.

do_replace_readwrite_async(etag, make_backup, flags, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously overwrites the file in read-write mode, replacing the contents, possibly creating a backup copy of the file first.

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

When the operation is finished, callback will be called. You can then call Gio.File.replace_readwrite_finish() to get the result of the operation.

New in version 2.22.

do_replace_readwrite_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a Gio.FileIOStream, or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.FileIOStream

Finishes an asynchronous file replace operation started with Gio.File.replace_readwrite_async().

New in version 2.22.

do_resolve_relative_path(relative_path) virtual
Parameters:

relative_path (str) – a given relative path string

Returns:

a Gio.File for the resolved path.

Return type:

Gio.File

Resolves a relative path for file to an absolute path.

This call does no blocking I/O.

If the relative_path is an absolute path name, the resolution is done absolutely (without taking file path as base).

do_set_attribute(attribute, type, value_p, flags, cancellable) virtual
Parameters:
Returns:

True if the attribute was set, False otherwise.

Return type:

bool

Sets an attribute in the file with attribute name attribute to value_p.

Some attributes can be unset by setting type to Gio.FileAttributeType.INVALID and value_p to None.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

do_set_attributes_async(info, flags, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously sets the attributes of file with info.

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

When the operation is finished, callback will be called. You can then call Gio.File.set_attributes_finish() to get the result of the operation.

do_set_attributes_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True if the attributes were set correctly, False otherwise.

info:

a Gio.FileInfo

Return type:

(bool, info: Gio.FileInfo)

Finishes setting an attribute started in Gio.File.set_attributes_async().

do_set_attributes_from_info(info, flags, cancellable) virtual
Parameters:
Returns:

False if there was any error, True otherwise.

Return type:

bool

Tries to set all attributes in the Gio.FileInfo on the target values, not stopping on the first error.

If there is any error during this operation then error will be set to the first error. Error on particular fields are flagged by setting the “status” field in the attribute value to Gio.FileAttributeStatus.ERROR_SETTING, which means you can also detect further errors.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

do_set_display_name(display_name, cancellable) virtual
Parameters:
Returns:

a Gio.File specifying what file was renamed to, or None if there was an error. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Renames file to the specified display name.

The display name is converted from UTF-8 to the correct encoding for the target filesystem if possible and the file is renamed to this.

If you want to implement a rename operation in the user interface the edit name (Gio.FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the initial value in the rename widget, and then the result after editing should be passed to Gio.File.set_display_name().

On success the resulting converted filename is returned.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

do_set_display_name_async(display_name, io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously sets the display name for a given Gio.File.

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

When the operation is finished, callback will be called. You can then call Gio.File.set_display_name_finish() to get the result of the operation.

do_set_display_name_finish(res) virtual
Parameters:

res (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

a Gio.File or None on error. Free the returned object with GObject.Object.unref().

Return type:

Gio.File

Finishes setting a display name started with Gio.File.set_display_name_async().

do_start_mountable(flags, start_operation, cancellable, callback, *user_data) virtual
Parameters:

Starts a file of type Gio.FileType.MOUNTABLE. Using start_operation, you can request callbacks when, for instance, passwords are needed during authentication.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.mount_mountable_finish() to get the result of the operation.

New in version 2.22.

do_start_mountable_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True if the operation finished successfully. False otherwise.

Return type:

bool

Finishes a start operation. See Gio.File.start_mountable() for details.

Finish an asynchronous start operation that was started with Gio.File.start_mountable().

New in version 2.22.

do_stop_mountable(flags, mount_operation, cancellable, callback, *user_data) virtual
Parameters:

Stops a file of type Gio.FileType.MOUNTABLE.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.stop_mountable_finish() to get the result of the operation.

New in version 2.22.

do_stop_mountable_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True if the operation finished successfully. False otherwise.

Return type:

bool

Finishes a stop operation, see Gio.File.stop_mountable() for details.

Finish an asynchronous stop operation that was started with Gio.File.stop_mountable().

New in version 2.22.

do_trash(cancellable) virtual
Parameters:

cancellable (Gio.Cancellable or None) – optional Gio.Cancellable object, None to ignore

Returns:

True on successful trash, False otherwise.

Return type:

bool

Sends file to the “Trashcan”, if possible. This is similar to deleting it, but the user can recover it before emptying the trashcan. Not all file systems support trashing, so this call can return the Gio.IOErrorEnum.NOT_SUPPORTED error. Since GLib 2.66, the x-gvfs-notrash unix mount option can be used to disable Gio.File.trash() support for certain mounts, the Gio.IOErrorEnum.NOT_SUPPORTED error will be returned in that case.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

do_trash_async(io_priority, cancellable, callback, *user_data) virtual
Parameters:

Asynchronously sends file to the Trash location, if possible.

New in version 2.38.

do_trash_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True on successful trash, False otherwise.

Return type:

bool

Finishes an asynchronous file trashing operation, started with Gio.File.trash_async().

New in version 2.38.

do_unmount_mountable(flags, cancellable, callback, *user_data) virtual
Parameters:

Unmounts a file of type Gio.FileType.MOUNTABLE.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.unmount_mountable_finish() to get the result of the operation.

Deprecated since version 2.22: Use Gio.File.unmount_mountable_with_operation() instead.

do_unmount_mountable_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True if the operation finished successfully. False otherwise.

Return type:

bool

Finishes an unmount operation, see Gio.File.unmount_mountable() for details.

Finish an asynchronous unmount operation that was started with Gio.File.unmount_mountable().

Deprecated since version 2.22: Use Gio.File.unmount_mountable_with_operation_finish() instead.

do_unmount_mountable_with_operation(flags, mount_operation, cancellable, callback, *user_data) virtual
Parameters:

Unmounts a file of type Gio.FileType.MOUNTABLE.

If cancellable is not None, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio.IOErrorEnum.CANCELLED will be returned.

When the operation is finished, callback will be called. You can then call Gio.File.unmount_mountable_finish() to get the result of the operation.

New in version 2.22.

do_unmount_mountable_with_operation_finish(result) virtual
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Returns:

True if the operation finished successfully. False otherwise.

Return type:

bool

Finishes an unmount operation, see Gio.File.unmount_mountable_with_operation() for details.

Finish an asynchronous unmount operation that was started with Gio.File.unmount_mountable_with_operation().

New in version 2.22.