gio.File — File and Directory Handling.
class gio.File(gobject.GInterface): |
Functions
def gio.file_parse_name(parse_name
)
gio.File
is a high
level abstraction for manipulating files on a virtual file system.
gio.File
s 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.File
s are extensible it
could also be something else that corresponds to a pathname in a userspace implementation of a filesystem.
gio.File
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
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.File
s.
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.File
s 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.File
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 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.File
s.
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.File
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 for HTTP Etag headers, which are a very similar concept.
gio.File(commandline
, path
=None, uri
=None)
| a command line string. |
| a string containing a relative or absolute path. |
| a string containing a URI. |
Returns : | a new
gio.File .
|
Creates a new gio.File
either from a commandline,
a path or an uri.
def append_to(flags
=gio.FILE_CREATE_NONE, cancellable
=None)
| a set of Gio File Create Flags Constants |
| 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.
def append_to_async(callback
, flags
=gio.FILE_CREATE_NONE, io_priority
=glib.PRIORITY_DEFAULT, cancellable
=None, user_data
=None)
| a GAsyncReadyCallback to call when the request is satisfied. |
| a set of Gio File Create Flags Constants. |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def append_to_finish(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
().
def copy(destination
, progress_callback
, flags
=gio.FILE_COPY_NONE, cancellable
=None, user_data
=None)
| destination gio.File .
|
| function to callback with progress information. |
| a set of Gio File Copy Flags Constants |
| optional
gio.Cancellable
object, None to ignore. |
| 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
().
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 gio.File .
|
| a GAsyncReadyCallback to call when the request is satisfied. |
| function to callback with progress information. |
| a set of Gio File Copy Flags Constants. |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| the data to pass to callback function. |
| 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.
def copy_attributes(destination
, flags
=gio.FILE_COPY_NONE, cancellable
=None)
| destination gio.File
to copy attributes to.
|
| a set of Gio File Copy Flags Constants |
| 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.
def copy_finish(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
().
def create(flags
=gio.FILE_CREATE_NONE, cancellable
=None)
| a set of Gio File Create Flags Constants |
| 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.
def create_async(callback
, flags
=gio.FILE_CREATE_NONE, io_priority
=glib.PRIORITY_DEFAULT, cancellable
=None, user_data
=None)
| a GAsyncReadyCallback to call when the request is satisfied. |
| a set of Gio File Copy Flags Constants. |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def create_finish(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
().
def delete(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.
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.
def eject_mountable(callback
, flags
=gio.FILE_CREATE_NONE, cancellable
=None, user_data
=None)
| a GAsyncReadyCallback to call when the request is satisfied. |
| a set of Gio File Copy Flags Constants. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def eject_mountable_finish(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
().
def enumerate_children(attributes
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None)
| an attribute query string. |
| a set of Gio File Query Info Flags Constants |
| 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.
def enumerate_children_async(attributes
, callback
, flags
=gio.FILE_QUERY_INFO_NONE, io_priority
=glib.PRIORITY_DEFAULT, cancellable
=None, user_data
=None)
| an attribute query string. |
| a GAsyncReadyCallback to call when the request is satisfied. |
| a set of Gio File Query Info Flags Constants. |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def enumerate_children_finish(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
().
def equal(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.File
s.
Note that two gio.File
s
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.
def enumerate_children(cancellable
=None)
| 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.
def find_enclosing_mount_async(callback
, io_priority
=glib.PRIORITY_DEFAULT, cancellable
=None, user_data
=None)
| a GAsyncReadyCallback to call when the request is satisfied. |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def find_enclosing_mount_finish(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
().
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.
def get_child(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.
def get_child_for_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.
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.
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.
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.
def get_relative_path(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.
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.
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.
def has_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.
def has_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.
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.
def load_contents(cancellable
=None)
| 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.
def load_contents_async(callback
, cancellable
=None, user_data
=None)
| a GAsyncReadyCallback to call when the request is satisfied. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def load_contents_finish(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
().
def make_directory(cancellable
=None)
| 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.
def make_directory_with_parents(cancellable
=None)
| 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.
def make_symbolic_link(symlink_value
, cancellable
=None)
| a string with the value of the new symlink. |
| 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.
def monitor(flags
=gio.FILE_MONITOR_NONE, cancellable
=None)
| a Gio File Monitor Flags Constants |
| 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.
def monitor_directory(flags
=gio.FILE_MONITOR_NONE, cancellable
=None)
| a Gio File Monitor Flags Constants |
| 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.
def monitor_file(flags
=gio.FILE_MONITOR_NONE, cancellable
=None)
| a Gio File Monitor Flags Constants |
| 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.
def mount_enclosing_volume(mount_operation
, callback
, flags
=gio.FILE_COPY_NONE, cancellable
=None, user_data
=None)
| a
gio.MountOperation
or None to avoid user interaction.
|
| a GAsyncReadyCallback to call when the request
is satisfied, or None .
|
| a set of Gio Mount Mount Flags Constants |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def mount_enclosing_volume_finish(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
().
def mount_mountable(mount_operation
, callback
, flags
=gio.FILE_COPY_NONE, cancellable
=None, user_data
=None)
| a
gio.MountOperation
or None to avoid user interaction.
|
| a GAsyncReadyCallback to call when the request
is satisfied, or None .
|
| a set of Gio Mount Mount Flags Constants |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def mount_mountable_finish(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
().
def copy(destination
, progress_callback
, flags
=gio.FILE_COPY_NONE, cancellable
=None, user_data
=None)
| destination gio.File .
|
| function to callback with progress information. |
| a set of Gio File Copy Flags Constants |
| optional
gio.Cancellable
object, None to ignore. |
| 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).
def query_default_handler(cancellable
=None)
| 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.
def query_exists(cancellable
=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).
|
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.
def query_file_type(flags
=gio.FILE_MONITOR_NONE, cancellable
=None)
| a Gio File Query Info Flags Constants |
| 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.
def query_filesystem_info(attributes
, cancellable
=None)
| an attribute query string. |
| 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.
def query_filesystem_info_async(attributes
, callback
, io_priority
=glib.PRIORITY_DEFAULT, cancellable
=None, user_data
=None)
| an attribute query string. |
| a GAsyncReadyCallback to call when the request is satisfied. |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def query_filesystem_info_finish(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
().
def query_info(attributes
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None)
| an attribute query string. |
| a Gio File Query Info Flags Constants |
| 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.
def query_info_async(attributes
, callback
, flags
=gio.FILE_QUERY_INFO_NONE, io_priority
=glib.PRIORITY_DEFAULT, cancellable
=None, user_data
=None)
| an attribute query string. |
| a GAsyncReadyCallback to call when the request is satisfied. |
| a Gio File Query Info Flags Constants |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def query_info_finish(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
().
def query_settable_attributes(cancellable
=None)
| 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.
def query_writable_namespace(cancellable
=None)
| 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.
def read(cancellable
=None)
| 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.
def read_async(callback
, io_priority
=glib.PRIORITY_DEFAULT, cancellable
=None, user_data
=None)
| a GAsyncReadyCallback to call when the request is satisfied. |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def read_finish(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
().
def replace(etag
, make_backup
, flags
=gio.FILE_CREATE_NONE, cancellable
=None)
| an optional entity tag for the current
gio.File ,
or None to ignore.
|
| True if a backup should be created.
|
| a set of Gio File Create Flags Constants |
| 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.
def replace_async(callback
, etag
=None, make_backup
=True, flags
=gio.FILE_CREATE_NONE, io_priority
=glib.PRIORITY_DEFAULT, cancellable
=None, user_data
=None)
| a GAsyncReadyCallback to call when the request is satisfied. |
| an optional entity tag for the current
gio.File ,
or None to ignore.
|
| True if a backup should be created.
|
| a set of Gio File Create Flags Constants |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def replace_contents(contents
, etag
, make_backup
, flags
=gio.FILE_CREATE_NONE, cancellable
=None)
| a string containing the new contents for file. |
| the old entity tag for the document
or None to ignore.
|
| True if a backup should be created.
|
| a set of Gio File Create Flags Constants |
| 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.
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)
| a string containing the new contents for file. |
| a GAsyncReadyCallback to call when the request is satisfied. |
| an optional entity tag for the current
gio.File ,
or None to ignore.
|
| True if a backup should be created.
|
| a set of Gio File Create Flags Constants |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def replace_contents_finish(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
().
def replace_finish(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
().
def resolve_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.
def set_attribute(attribute
, type
, value_p
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None)
| a string containing the attribute's name. |
| the type of the attribute . |
| the value. |
| a set of Gio File Query Info Flags Constants |
| 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.
def set_attribute_byte_string(attribute
, value
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None)
| a string containing the attribute's name. |
| a string containing the attribute's new value. |
| a set of Gio File Query Info Flags Constants |
| 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.
def set_attribute_int32(attribute
, value
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None)
| a string containing the attribute's name. |
| an int containing the attribute's new value. |
| a set of Gio File Query Info Flags Constants |
| 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.
def set_attribute_int64(attribute
, value
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None)
| a string containing the attribute's name. |
| a long containing the attribute's new value. |
| a set of Gio File Query Info Flags Constants |
| 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.
def set_attribute_string(attribute
, value
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None)
| a string containing the attribute's name. |
| a string containing the attribute's new value. |
| a set of Gio File Query Info Flags Constants |
| 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.
def set_attribute_uint32(attribute
, value
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None)
| a string containing the attribute's name. |
| an int containing the attribute's new value. |
| a set of Gio File Query Info Flags Constants |
| 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.
def set_attribute_uint64(attribute
, value
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None)
| a string containing the attribute's name. |
| a long containing the attribute's new value. |
| a set of Gio File Query Info Flags Constants |
| 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.
def set_attributes_async(info
, callback
, flags
=gio.FILE_QUERY_INFO_NONE, io_priority
=glib.PRIORITY_DEFAULT, cancellable
=None, user_data
=None)
| a gio.FileInfo
|
| a GAsyncReadyCallback to call when the request is satisfied. |
| a set of Gio File Query Info Flags Constants |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def set_attributes_finish(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
().
def set_attributes_from_info(info
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None)
| a gio.FileInfo
|
| a set of Gio File Query Info Flags Constants |
| 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 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.
def set_display_name(display_name
, cancellable
=None)
| a string conaining the name to display. |
| 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.
def set_display_name_async(display_name
, callback
, io_priority
=glib.PRIORITY_DEFAULT, cancellable
=None, user_data
=None)
| a string conaining the name to display. |
| a GAsyncReadyCallback to call when the request is satisfied. |
| the Glib Priority Constants of the request. |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def set_display_name_finish(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
().
def trash(cancellable
=None)
| 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.
def unmount_mountable(callback
, flags
=gio.FILE_QUERY_INFO_NONE, cancellable
=None, user_data
=None)
| a GAsyncReadyCallback to call when the request is satisfied. |
| a set of Gio File Query Info Flags Constants |
| optional
gio.Cancellable
object, None to ignore. |
| 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.
def unmount_mountable_finish(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
().
def file_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.