manpagez: man pages & more
html files: pygobject
Home | html | info | man
): gio.File(commandline, path=None, uri=None)
def append_to(flags=gio.FILE_CREATE_NONE, cancellable=None)
def append_to_async(callback, flags=gio.FILE_CREATE_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def append_to_finish(result)
def copy(destination, progress_callback, flags=gio.FILE_COPY_NONE, cancellable=None, user_data=None)
def copy_async(destination, callback, progress_callback=None, flags=gio.FILE_CREATE_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None, progress_callback_data=None)
def copy_attributes(destination, flags=gio.FILE_COPY_NONE, cancellable=None)
def copy_finish(result)
def create(flags=gio.FILE_CREATE_NONE, cancellable=None)
def create_async(callback, flags=gio.FILE_CREATE_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def create_finish(result)
def delete(cancellable=None)
def dup()
def eject_mountable(callback, flags=gio.FILE_CREATE_NONE, cancellable=None, user_data=None)
def eject_mountable_finish(result)
def enumerate_children(attributes, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)
def enumerate_children_async(attributes, callback, flags=gio.FILE_QUERY_INFO_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def enumerate_children_finish(result)
def equal(file2)
def find_enclosing_mount(cancellable)
def find_enclosing_mount_async(callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def find_enclosing_mount_finish(result)
def get_basename()
def get_child(name)
def get_child_for_display_name(display_name)
def get_parent()
def get_parse_name()
def get_path()
def get_relative_path(descendant)
def get_uri()
def get_uri_scheme()
def has_prefix(prefix)
def has_uri_scheme(uri_scheme)
def is_native()
def load_contents(cancellable)
def load_contents_async(callback, cancellable=None, user_data=None)
def load_contents_finish(result)
def make_directory(cancellable=None)
def make_directory_with_parents(cancellable=None)
def make_symbolic_link(symlink_value, cancellable)
def monitor(flags=gio.FILE_MONITOR_NONE, cancellable=None)
def monitor_directory(flags, cancellable=None)
def monitor_file(flags, cancellable=None)
def mount_enclosing_volume(mount_operation, callback, flags=gio.MOUNT_MOUNT_NONE, cancellable=None, user_data=None)
def mount_enclosing_volume_finish(result)
def mount_mountable(mount_operation, callback, flags=gio.MOUNT_MOUNT_NONE, cancellable=None, user_data=None)
def mount_mountable_finish(result)
def move(destination, progress_callback, flags=gio.FILE_COPY_NONE, cancellable=None, user_data=None)
def query_default_handler(cancellable)
def query_exists(cancellable)
def query_file_type(flags, cancellable)
def query_filesystem_info(attributes, cancellable)
def query_filesystem_info_async(attributes, callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def query_filesystem_info_finish(result)
def query_info(attributes, flags, cancellable)
def query_info_async(attributes, callback, flags=gio.FILE_QUERY_INFO_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def query_info_finish(result)
def query_settable_attributes(cancellable=None)
def query_writable_namespace(cancellable=None)
def read(cancellable=None)
def read_async(callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def read_finish(result=None)
def replace(etag, make_backup, flags=gio.FILE_CREATE_NONE, cancellable=None)
def replace_async(callback, etag=None, make_backup=True, flags=gio.FILE_CREATE_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def replace_contents(contents, etag=None, make_backup=True, flags=gio.FILE_CREATE_NONE, cancellable=None)
def replace_contents_async(contents, callback, etag=None, make_backup=True, flags=gio.FILE_CREATE_NONE, cancellable=None, user_data=None)
def replace_contents_finish(result=None)
def replace_finish(result=None)
def resolve_relative_path(relative_path)
def set_attribute(attribute, type, value_p, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)
def set_attribute_byte_string(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)
def set_attribute_int32(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)
def set_attribute_int64(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)
def set_attribute_string(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)
def set_attribute_uint32(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)
def set_attribute_uint64(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)
def set_attributes_async(info, callback, flags=gio.FILE_QUERY_INFO_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def set_attributes_finish(result)
def set_attributes_from_info(info, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)
def set_dispay_name(display_name, cancellable=None)
def set_display_name_async(display_name, callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)
def set_display_name_finish(result)
def trash(cancellable=None)
def unmount_mountable(callback, flags=gio.MOUNT_UNMOUNT_NONE, cancellable=None, user_data=None)
def unmount_mountable_finish(cancellable=None)
Functions
    def gio.file_parse_name(parse_name)

Ancestry

+-- gobject.GInterface
  +-- gio.File

Prerequisites

gio.File is implemented by gobject.GObject

Description

gio.File is a high level abstraction for manipulating files on a virtual file system. gio.Files are lightweight, immutable objects that do no I/O upon creation. It is necessary to understand that gio.File objects do not represent files, merely an identifier for a file. All file content I/O is implemented as streaming operations (see gio.InputStream and gio.OutputStream).

To construct a gio.File, you can use it's constructor either with a path, an uri or a commandline argument. gio.file_parse_name() from a utf8 string gotten from gio.File.get_parse_name().

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

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

All gio.Files have a basename (get with 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 gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with gio.File.query_info(). This is guaranteed to be in utf8 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 gio.File 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 gio.Files to refer to the same file. Other possible causes for aliases are: case insensitive filesystems, short and long names on Fat/NTFS, or bind mounts in Linux. If you want to check if two GFiles point to the same file you can query for the gio.FILE_ATTRIBUTE_ID_FILE attribute. Note that gio.File 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 gio.Files.

Many gio.File 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 GAsyncReadyCallback which is then used to finalize the operation, producing a GAsyncResult which is then passed to the function's matching _finish() operation.

Some gio.File operations do not have synchronous analogs, as they may take a very long time to finish, and blocking may leave an application unusable. Notable cases include: gio.File.mount_mountable() to mount a mountable file. gio.File.unmount_mountable() to unmount a mountable file. gio.File.eject_mountable() to eject a mountable file.

One notable feature of gio.Files 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 for HTTP Etag headers, which are a very similar concept.

Constructor

    gio.File(commandline, path=None, uri=None)

commandline :

a command line string.

path :

a string containing a relative or absolute path.

uri :

a string containing a URI.

Returns :

a new gio.File.

Creates a new gio.File either from a commandline, a path or an uri.

Methods

gio.File.append_to

    def append_to(flags=gio.FILE_CREATE_NONE, cancellable=None)

flags :

a set of Gio File Create Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.FileOutputStream or None on error.

The append_to() method 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.FILE_CREATE_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.ERROR_CANCELLED will be returned.

Some file systems don't allow all file names, and may return an gio.ERROR_INVALID_FILENAME error. If the file is a directory the gio.ERROR_IS_DIRECTORY error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

gio.File.append_to_async

    def append_to_async(callback, flags=gio.FILE_CREATE_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

callback :

a GAsyncReadyCallback to call when the request is satisfied.

flags :

a set of Gio File Create Flags Constants.

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The append_to_async() method 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.

gio.File.append_to_finish

    def append_to_finish(result)

result :

a gio.AsyncResult.

Returns :

a valid gio.OutputStream or None on error.

The append_to_finish() method finishes an asynchronous file append operation started with gio.File.append_to_async().

gio.File.copy

    def copy(destination, progress_callback, flags=gio.FILE_COPY_NONE, cancellable=None, user_data=None)

destination :

destination gio.File.

progress_callback :

function to callback with progress information.

flags :

a set of Gio File Copy Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to the progress callback function.

Returns :

True on success, False otherwise.

The copy() method copies the file source to the location specified by destination. Can not handle recursive copies of directories.

If the flag gio.FILE_COPY_OVERWRITE is specified an already existing destination file is overwritten.

If the flag gio.FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks will be copied as symlinks, otherwise the target of the source symlink will be copied.

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.ERROR_CANCELLED will be returned.

If progress_callback is not None, then the operation can be monitored by setting this to a GFileProgressCallback function. user_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.ERROR_NOT_FOUND error is returned, independent on the status of the destination.

If gio.FILE_COPY_OVERWRITE is not specified and the target exists, then the error gio.ERROR_EXISTS is returned.

If trying to overwrite a file over a directory the gio.ERROR_IS_DIRECTORY error is returned. If trying to overwrite a directory with a directory the gio.ERROR_WOULD_MERGE error is returned.

If the source is a directory and the target does not exist, or gio.FILE_COPY_OVERWRITE is specified and the target is a file, then the gio.ERROR_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().

gio.File.copy_async

    def append_to_async(destination, callback, progress_callback=None, flags=gio.FILE_CREATE_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None, progress_callback_data=None)

destination :

destination gio.File.

callback :

a GAsyncReadyCallback to call when the request is satisfied.

progress_callback :

function to callback with progress information.

flags :

a set of Gio File Copy Flags Constants.

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

progress_callback_data :

the data to pass to the progress callback function.

The copy_async() method 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(), however the callback will run in the main loop, not in the thread that is doing the I/O operation.

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

gio.File.copy_attributes

    def copy_attributes(destination, flags=gio.FILE_COPY_NONE, cancellable=None)

destination :

destination gio.File to copy attributes to.

flags :

a set of Gio File Copy Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True if the attributes were copied successfully, False otherwise.

The copy_attributes() method copies the file attributes from source to destination.

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

gio.File.copy_finish

    def copy_finish(result)

result :

a gio.AsyncResult.

Returns :

True on success, False on error.

The copy_finish() method finishes an asynchronous copy operation started with gio.File.copy_async().

gio.File.create

    def create(flags=gio.FILE_CREATE_NONE, cancellable=None)

flags :

a set of Gio File Create Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.FileOutputStream or None on error.

The create() method 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.FILE_CREATE_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.ERROR_CANCELLED will be returned.

If a file or directory with this name already exists the gio.ERROR_EXISTS error will be returned. Some file systems don't allow all file names, and may return an gio.ERROR_INVALID_FILENAME error, and if the name is to long gio.ERROR_FILENAME_TOO_LONG will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

gio.File.create_async

    def create_async(callback, flags=gio.FILE_CREATE_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

callback :

a GAsyncReadyCallback to call when the request is satisfied.

flags :

a set of Gio File Copy Flags Constants.

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The create_async() method 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.

gio.File.create_finish

    def create_finish(result)

result :

a gio.AsyncResult.

Returns :

a gio.FileOutputStream or None on error.

The create_finish() method finishes an asynchronous copy operation started with gio.File.create_async().

gio.File.delete

    def delete(cancellable)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True if the file was deleted, False otherwise.

The deleted() method deletes a file. If the file is a directory, it will only be deleted if it is empty.

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.ERROR_CANCELLED will be returned.

gio.File.dup

    def dup()

Returns :

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

The dup() method 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.

This call does no blocking i/o.

gio.File.eject_mountable

    def eject_mountable(callback, flags=gio.FILE_CREATE_NONE, cancellable=None, user_data=None)

callback :

a GAsyncReadyCallback to call when the request is satisfied.

flags :

a set of Gio File Copy Flags Constants.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The eject_mountable() method 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.ERROR_CANCELLED will be returned.

gio.File.eject_mountable_finish

    def eject_mountable_finish(result)

result :

a gio.AsyncResult.

Returns :

True if the file was ejected successfully, False on error.

The create_finish() method finishes an asynchronous copy operation started with gio.File.create_async().

gio.File.enumerate_children

    def enumerate_children(attributes, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)

attributes :

an attribute query string.

flags :

a set of Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.FileEnumerator or None on error.

The enumerate_children() method gets the requested information about the files in a directory. The result is a GFileEnumerator object that will give out gio.FileInfo objects for all the files in the directory.

The attribute 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. attribute should be a comma-separated list of attribute 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.ERROR_CANCELLED will be returned.

If the file does not exist, the gio.ERROR_NOT_FOUND error will be returned. If the file is not a directory, the gio.FILE_ERROR_NOTDIR error will be returned. Other errors are possible too.

gio.File.enumerate_children_async

    def enumerate_children_async(attributes, callback, flags=gio.FILE_QUERY_INFO_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

attributes :

an attribute query string.

callback :

a GAsyncReadyCallback to call when the request is satisfied.

flags :

a set of Gio File Query Info Flags Constants.

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The enumerate_children_async() method 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 enumerate_children() which is the synchronous version of this call.

gio.File.eject_mountable_finish

    def enumerate_children_finish(result)

result :

a gio.AsyncResult.

Returns :

a gio.FileEnumerator or None if an error occurred.

The enumerate_children_finish() method finishes an asynchronous copy operation started with gio.File.enumerate_children_async().

gio.File.equal

    def equal(file2)

file2 :

a gio.File.

Returns :

True if file1 and file2 are equal. False if either is not a gio.File.

The equal() method checks equality of two given gio.Files. 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.

gio.File.find_enclosing_mount

    def enumerate_children(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.Mount or None on error.

The find_enclosing_mount() method gets a gio.Mount for the gio.File.

If the interface for file does not have a mount (e.g. possibly a remote share), error will be set to gio.ERROR_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.ERROR_CANCELLED will be returned.

gio.File.find_enclosing_mount_async

    def find_enclosing_mount_async(callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

callback :

a GAsyncReadyCallback to call when the request is satisfied.

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The find_enclosing_mount_async() method asynchronously gets the mount for the file.

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

gio.File.find_enclosing_mount_finish

    def find_enclosing_mount_finish(result)

result :

a gio.AsyncResult.

Returns :

a gio.Mount or None if an error occurred.

The find_enclosing_mount_finish() method finishes an asynchronous find mount started with gio.File.find_enclosing_mount_async().

gio.File.get_basename

    def get_basename()

Returns :

string containing the gio.File's base name, or None if given gio.File is invalid.

The get_basename() method 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.

gio.File.get_child

    def get_child(name)

name :

string containing the child's basename.

Returns :

a gio.File to a child specified by name.

The get_child() method gets a child of file with basename equal to name.

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

This call does no blocking i/o.

gio.File.get_child_for_display_name

    def get_child_for_display_name(display_name)

display_name :

string to a possible child.

Returns :

a gio.File to the specified child or None if the display name couldn't be converted.

The get_child_for_display_name() method gets the child of file for a given display_name (i.e. a UTF8 version of the name). If this function fails, it returns NULL and error will be set. This is very useful when constructing a GFile 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.

gio.File.get_parent

    def get_parent()

Returns :

a gio.File structure to the parent of the given gio.File or None if there is no parent.

The get_parent() method 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.

gio.File.get_parse_name

    def get_parse_name()

Returns :

a string containing the gio.File's parse name.

The get_parse_name() method 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 UTF8 the pathname is used, otherwise the IRI is used (a form of URI that allows UTF8 characters unescaped).

This call does no blocking i/o.

gio.File.get_path

    def get_path()

Returns :

a string containing the gio.File's path, or None if no such path exists.

The get_path() method gets the local pathname for gio.File, if one exists.

This call does no blocking i/o.

gio.File.get_relative_path

    def get_relative_path(descendant)

descendant :

input gio.File.

Returns :

string with the relative path from descendant to parent, or None if descendant doesn't have parent as prefix.

The get_relative_path() method gets the path for descendant relative to parent.

This call does no blocking i/o.

gio.File.get_uri

    def get_uri()

Returns :

a string containing the gio.File's URI.

The get_uri() method gets the URI for the file.

This call does no blocking i/o.

gio.File.get_uri_scheme

    def get_uri_scheme()

Returns :

a string containing the URI scheme for the gio.File.

The get_uri_scheme() method 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.

This call does no blocking i/o.

gio.File.has_prefix

    def has_prefix(prefix)

prefix :

input gio.File.

Returns :

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

The has_prefix() method checks whether file has the prefix specified by prefix. In other word, if the names of inital elements of files 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.

This call does no blocking 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.

gio.File.has_uri_scheme

    def has_uri_scheme(uri_scheme)

uri_scheme :

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.

The has_uri_scheme() method checks to see if a gio.File has a given URI scheme.

This call does no blocking i/o.

gio.File.is_native

    def is_native()

Returns :

True if file is native.

The is_native() method checks to see if a file is native to the platform.

A native file s 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.

gio.File.load_contents

    def load_contents(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a three tuple containing the contents of the file, the length of the contents of the file and the current entity tag for the file.

The load_contents() method loads the content of the file into memory. The data is always zero-terminated, but this is not included in the resultant length.

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.ERROR_CANCELLED will be returned.

gio.File.load_contents_async

    def load_contents_async(callback, cancellable=None, user_data=None)

callback :

a GAsyncReadyCallback to call when the request is satisfied.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The load_contents_async() method starts an asynchronous load of the file'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 GAsyncResult returned by the callback.

gio.File.load_contents_finish

    def load_contents_finish(result)

result :

a gio.AsyncResult.

Returns :

a three tuple containing the contents of the file, the length of the contents of the file and the current entity tag for the file.

The load_contents_finish() method finishes an asynchronous find mount started with gio.File.load_contents_async().

gio.File.make_directory

    def make_directory(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True on successful creation, False otherwise.

The make_directory() method 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.ERROR_NOT_FOUND. If the file system doesn't support creating directories, this function will fail, setting error to gio.ERROR_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.ERROR_CANCELLED will be returned.

gio.File.make_directory_with_parents

    def make_directory_with_parents(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

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

The make_directory_with_parents() method 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.ERROR_NOT_SUPPORTED.

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.ERROR_CANCELLED will be returned.

gio.File.make_symbolic_link

    def make_symbolic_link(symlink_value, cancellable=None)

symlink_value :

a string with the value of the new symlink.

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

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

The make_symbolic_link() method creates a symbolic link.

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.ERROR_CANCELLED will be returned.

gio.File.monitor

    def monitor(flags=gio.FILE_MONITOR_NONE, cancellable=None)

flags :

a Gio File Monitor Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.FileMonitor for the given file, or None on error

The monitor() method 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.ERROR_CANCELLED will be returned.

gio.File.monitor_directory

    def monitor_directory(flags=gio.FILE_MONITOR_NONE, cancellable=None)

flags :

a Gio File Monitor Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.FileMonitor for the given file, or None on error

The monitor_directory() method 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.ERROR_CANCELLED will be returned.

gio.File.monitor_file

    def monitor_file(flags=gio.FILE_MONITOR_NONE, cancellable=None)

flags :

a Gio File Monitor Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.FileMonitor for the given file, or None on error

The monitor_file() method 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.ERROR_CANCELLED will be returned.

gio.File.mount_enclosing_volume

    def mount_enclosing_volume(mount_operation, callback, flags=gio.FILE_COPY_NONE, cancellable=None, user_data=None)

mount_operation :

a gio.MountOperation or None to avoid user interaction.

callback :

a GAsyncReadyCallback to call when the request is satisfied, or None.

flags :

a set of Gio Mount Mount Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to the progress callback function.

The mount_enclosing_volume() method 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.ERROR_CANCELLED will be returned.

gio.File.mount_enclosing_volume_finish

    def mount_enclosing_volume_finish(result)

result :

a gio.AsyncResult.

Returns :

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

The mount_enclosing_volume_finish() method finishes an asynchronous find mount started with gio.File.mount_enclosing_volume().

gio.File.mount_mountable

    def mount_mountable(mount_operation, callback, flags=gio.FILE_COPY_NONE, cancellable=None, user_data=None)

mount_operation :

a gio.MountOperation or None to avoid user interaction.

callback :

a GAsyncReadyCallback to call when the request is satisfied, or None.

flags :

a set of Gio Mount Mount Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to the progress callback function.

The mount_mountable() method mounts a file of type gio.FILE_TYPE_MOUNTABLE. Using mount_operation, you can request callbacks when, for instance, passwords are needed during authentication.

When this operation has completed, callback will be called with user_user data, and the operation can be finalized with gio.File.mount_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.ERROR_CANCELLED will be returned.

gio.File.mount_mountable_finish

    def mount_mountable_finish(result)

result :

a gio.AsyncResult.

Returns :

a gio.File or None on error.

The mount_mountable_finish() method finishes an asynchronous find mount started with gio.File.mount_mountable().

gio.File.move

    def copy(destination, progress_callback, flags=gio.FILE_COPY_NONE, cancellable=None, user_data=None)

destination :

destination gio.File.

progress_callback :

function to callback with progress information.

flags :

a set of Gio File Copy Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to the progress callback function.

Returns :

True on success, False otherwise.

The move() method 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.FILE_COPY_OVERWRITE is specified an already existing destination file is overwritten.

If the flag gio.FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks will be copied as symlinks, otherwise the target of the source symlink will be copied.

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.ERROR_CANCELLED will be returned.

If progress_callback is not None, then the operation can be monitored by setting this to a GFileProgressCallback 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.ERROR_NOT_FOUND error is returned, independent on the status of the destination.

If gio.FILE_COPY_OVERWRITE is not specified and the target exists, then the error gio.ERROR_EXISTS is returned.

If trying to overwrite a file over a directory the gio.ERROR_IS_DIRECTORY error is returned. If trying to overwrite a directory with a directory the gio.ERROR_WOULD_MERGE error is returned.

If the source is a directory and the target does not exist, or gio.FILE_COPY_OVERWRITE is specified and the target is a file, then the gio.ERROR_WOULD_RECURSE error may be returned (if the native move operation isn't available).

gio.File.query_default_handler

    def query_default_handler(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.AppInfo if the handle was found, None if there were errors.

The query_default_handler() method returns the gio.AppInfo that is registered as the default application to handle the file specified by 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.ERROR_CANCELLED will be returned.

gio.File.query_exists

    def query_exists(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

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

The query_exists() method is an tility 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.ERROR_EXISTS error.

However, in many cases an existence check is useful in a user interface, for instance to make a menu item sensitive/insensitive, so that you don't have to fool users that something is possible and then just show and 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.

gio.File.query_file_type

    def query_file_type(flags=gio.FILE_MONITOR_NONE, cancellable=None)

flags :

a Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

Gio File Type Constants

The query_file_type() method it's an utility function to inspect the Gio File Query Info Flags Constants 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.

gio.File.query_filesystem_info

    def query_filesystem_info(attributes, cancellable=None)

attributes :

an attribute query string.

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.FileInfo or None if there was an error.

The query_filesystem_info() method it's 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 attribute 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. attribute should be a comma-separated list of attribute or attribute wildcards. The wildcard "*" means all attributes, and a wildcard like "fs:*" means all attributes in the fs namespace. The standard namespace for filesystem attributes is "fs". 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.ERROR_CANCELLED will be returned.

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

gio.File.query_filesystem_info_async

    def query_filesystem_info_async(attributes, callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

attributes :

an attribute query string.

callback :

a GAsyncReadyCallback to call when the request is satisfied.

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

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

For more details, see 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_filesystem_info_finish() to get the result of the operation.

gio.File.query_filesystem_info_finish

    def query_filesystem_info_finish(result)

result :

a gio.AsyncResult.

Returns :

a gio.FileInfo or None if an error occurred.

The query_filesystem_info_finish() method finishes an asynchronous copy operation started with gio.File.query_filesystem_info_async().

gio.File.query_filesystem_info

    def query_info(attributes, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)

attributes :

an attribute query string.

flags :

a Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.FileInfo for the given file or None if there was an error.

The query_info() method 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 attribute 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. attribute should be a comma-separated list of attribute 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.ERROR_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.FILE_QUERY_INFO_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.ERROR_NOT_FOUND error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

gio.File.query_info_async

    def query_info_async(attributes, callback, flags=gio.FILE_QUERY_INFO_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

attributes :

an attribute query string.

callback :

a GAsyncReadyCallback to call when the request is satisfied.

flags :

a Gio File Query Info Flags Constants

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The query_info_async() method 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 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.

gio.File.query_info_finish

    def query_info_finish(result)

result :

a gio.AsyncResult.

Returns :

a gio.FileInfo for the given file or None if an error occurred.

The query_info_finish() method finishes an asynchronous copy operation started with gio.File.query_info_async().

gio.File.query_settable_attributes

    def query_settable_attributes(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a list of gio.FileAttributeInfo describing the settable attributes.

The query_settable_attributes() method 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.ERROR_CANCELLED will be returned.

gio.File.query_writable_namespace

    def query_writable_namespace(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a list of gio.FileAttributeInfo describing the writable namespaces.

The query_writable_namespace() method 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.ERROR_CANCELLED will be returned.

gio.File.read

    def read(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.FileInputStream or None on error.

The read() method 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.ERROR_CANCELLED will be returned.

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

gio.File.read_async

    def read_async(callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

callback :

a GAsyncReadyCallback to call when the request is satisfied.

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The read_async() method asynchronously opens file for reading.

For more details, see 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.

gio.File.read_finish

    def read_finish(result)

result :

a gio.AsyncResult.

Returns :

a gio.FileInputStream file or None if an error occurred.

The read_finish() method finishes an asynchronous copy operation started with gio.File.read_async().

gio.File.replace

    def replace(etag, make_backup, flags=gio.FILE_CREATE_NONE, cancellable=None)

etag :

an optional entity tag for the current gio.File, or None to ignore.

make_backup :

True if a backup should be created.

flags :

a set of Gio File Create Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.FileOutputStream or None on error.

The replace() method 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.FILE_CREATE_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.ERROR_CANCELLED will be returned.

If you pass in a non-None etag value, then this value is compared to the current entity tag of the file, and if they differ an gio.ERROR_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 GFileOutputStream. 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.ERROR_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.ERROR_IS_DIRECTORY error will be returned, and if the file is some other form of non-regular file then a gio.ERROR_NOT_REGULAR_FILE error will be returned. Some file systems don't allow all file names, and may return an gio.ERROR_INVALID_FILENAME error, and if the name is to long gio.ERROR_FILENAME_TOO_LONG will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.

gio.File.replace_async

    def replace_async(callback, etag=None, make_backup=True, flags=gio.FILE_CREATE_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

callback :

a GAsyncReadyCallback to call when the request is satisfied.

etag :

an optional entity tag for the current gio.File, or None to ignore.

make_backup :

True if a backup should be created.

flags :

a set of Gio File Create Flags Constants

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The replace_async() method asynchronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first.

For more details, see 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.

gio.File.replace_contents

    def replace_contents(contents, etag, make_backup, flags=gio.FILE_CREATE_NONE, cancellable=None)

contents :

a string containing the new contents for file.

etag :

the old entity tag for the document or None to ignore.

make_backup :

True if a backup should be created.

flags :

a set of Gio File Create Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

the new entity tag for the document.

The replace_contents() method replaces the contents of file with contents of length bytes. If etag is specified (not NULL) any existing file must have that etag, or the error gio.ERROR_WRONG_ETAG will be returned.

If make_backup is True, this function will attempt to make a backup of 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.ERROR_CANCELLED will be returned.

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

gio.File.replace_contents_async

    def replace_contents_async(contents, callback, etag=None, make_backup=True, flags=gio.FILE_CREATE_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

contents :

a string containing the new contents for file.

callback :

a GAsyncReadyCallback to call when the request is satisfied.

etag :

an optional entity tag for the current gio.File, or None to ignore.

make_backup :

True if a backup should be created.

flags :

a set of Gio File Create Flags Constants

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The replace_contents_async() method starts an asynchronous replacement of file with the given contents of length bytes. etag will replace the document's current entity tag.

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

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

gio.File.replace_contents_finish

    def replace_contents_finish(result)

result :

a gio.AsyncResult.

Returns :

the new entity tag for the document.

The replace_contents_finish() method finishes an asynchronous copy operation started with gio.File.replace_contents_async().

gio.File.replace_finish

    def replace_finish(result)

result :

a gio.AsyncResult.

Returns :

a gio.FileOutputStream or None if an error occurred.

The replace_finish() method finishes an asynchronous copy operation started with gio.File.replace_async().

gio.File.resolve_relative_path

    def resolve_relative_path(relative_path)

relative_path :

a given relative path string.

Returns :

a gio.File to the resolved path. None if relative_path is None or if file is invalid.

The resolve_relative_path() method resolves a relative path for file to an absolute path.

This call does no blocking i/o.

gio.File.set_attribute

    def set_attribute(attribute, type, value_p, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)

attribute :

a string containing the attribute's name.

type :

the type of the attribute .

value_p :

the value.

flags :

a set of Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True if the attribute was set, False otherwise.

The set_attribute() method sets an attribute in the file with attribute name attribute to 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.ERROR_CANCELLED will be returned.

gio.File.set_attribute_byte_string

    def set_attribute_byte_string(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)

attribute :

a string containing the attribute's name.

value :

a string containing the attribute's new value.

flags :

a set of Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True if the attribute was set, False otherwise.

The set_attribute_byte_string() method Sets attribute of type gio.FILE_ATTRIBUTE_TYPE_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.ERROR_CANCELLED will be returned.

gio.File.set_attribute_int32

    def set_attribute_int32(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)

attribute :

a string containing the attribute's name.

value :

an int containing the attribute's new value.

flags :

a set of Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True if the attribute was set, False otherwise.

The set_attribute_int32() method sets attribute of type gio.FILE_ATTRIBUTE_TYPE_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.ERROR_CANCELLED will be returned.

gio.File.set_attribute_int64

    def set_attribute_int64(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)

attribute :

a string containing the attribute's name.

value :

a long containing the attribute's new value.

flags :

a set of Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True if the attribute was set, False otherwise.

The set_attribute_int64() method sets attribute of type gio.FILE_ATTRIBUTE_TYPE_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.ERROR_CANCELLED will be returned.

gio.File.set_attribute_string

    def set_attribute_string(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)

attribute :

a string containing the attribute's name.

value :

a string containing the attribute's new value.

flags :

a set of Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True if the attribute was set, False otherwise.

The set_attribute_string() method sets attribute of type gio.FILE_ATTRIBUTE_TYPE_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.ERROR_CANCELLED will be returned.

gio.File.set_attribute_uint32

    def set_attribute_uint32(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)

attribute :

a string containing the attribute's name.

value :

an int containing the attribute's new value.

flags :

a set of Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True if the attribute was set, False otherwise.

The set_attribute_uint32() method sets attribute of type gio.FILE_ATTRIBUTE_TYPE_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.ERROR_CANCELLED will be returned.

gio.File.set_attribute_uint64

    def set_attribute_uint64(attribute, value, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)

attribute :

a string containing the attribute's name.

value :

a long containing the attribute's new value.

flags :

a set of Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True if the attribute was set, False otherwise.

The set_attribute_uint64() method sets attribute of type gio.FILE_ATTRIBUTE_TYPE_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.ERROR_CANCELLED will be returned.

gio.File.set_attributes_async

    def set_attributes_async(info, callback, flags=gio.FILE_QUERY_INFO_NONE, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

info :

a gio.FileInfo

callback :

a GAsyncReadyCallback to call when the request is satisfied.

flags :

a set of Gio File Query Info Flags Constants

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The set_attributes_async() method asynchronously sets the attributes of file with info.

For more details, see 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.

gio.File.set_attributes_finish

    def set_attributes_finish(result)

result :

a gio.AsyncResult.

Returns :

True if the attributes were set correctly, False otherwise.

The set_attributes_finish() method finishes an asynchronous copy operation started with gio.File.set_attributes_async().

gio.File.set_attributes_from_info

    def set_attributes_from_info(info, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None)

info :

a gio.FileInfo

flags :

a set of Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True if the attributes were set correctly, False otherwise.

The set_attributes_from_info() method tries to set all attributes in the GFileInfo 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.FILE_ATTRIBUTE_STATUS_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.ERROR_CANCELLED will be returned.

gio.File.set_display_name

    def set_display_name(display_name, cancellable=None)

display_name :

a string conaining the name to display.

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

a gio.File specifying what file was renamed to, or None if there was an error.

The set_display_name() method renames file to the specified display name.

The display name is converted from UTF8 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_dispay_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.ERROR_CANCELLED will be returned.

gio.File.set_display_name_async

    def set_display_name_async(display_name, callback, io_priority=glib.PRIORITY_DEFAULT, cancellable=None, user_data=None)

display_name :

a string conaining the name to display.

callback :

a GAsyncReadyCallback to call when the request is satisfied.

io_priority :

the Glib Priority Constants of the request.

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The set_display_name_async() method asynchronously sets the display name for a given GFile.

For more details, see 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.

gio.File.set_display_name_finish

    def set_display_name_finish(result)

result :

a gio.AsyncResult.

Returns :

a gio.File or None on error.

The set_display_name_finish() method finishes an asynchronous copy operation started with gio.File.set_display_name_async().

gio.File.trash

    def trash(cancellable=None)

cancellable :

optional gio.Cancellable object, None to ignore.

Returns :

True on successful trash, False otherwise.

The trash() method 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.ERROR_NOT_SUPPORTED error.

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.ERROR_CANCELLED will be returned.

gio.File.unmount_mountable

    def unmount_mountable(callback, flags=gio.FILE_QUERY_INFO_NONE, cancellable=None, user_data=None)

callback :

a GAsyncReadyCallback to call when the request is satisfied.

flags :

a set of Gio File Query Info Flags Constants

cancellable :

optional gio.Cancellable object, None to ignore.

user_data :

the data to pass to callback function.

The unmount_mountable() method unmounts a file of type gio.FILE_TYPE_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.ERROR_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.

gio.File.unmount_mountable_finish

    def unmount_mountable_finish(result)

result :

a gio.AsyncResult.

Returns :

True if the operation finished successfully, False otherwise.

The unmount_mountable_finish() method finishes an asynchronous copy operation started with gio.File.unmount_mountable().

Functions

gio.file_parse_name

    def file_parse_name(parse_name)

parse_name :

a file name or path to be parsed.

Returns :

a new gio.File.

The parse_name() function constructs a gio.File with the given parse_name (i.e. something given by g_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.