gio.FileInformation about an installed application and methods to launch it (with file arguments).Synopsisgio.Filegobject.GInterfacegio.FilecommandlinepathNoneuriNoneappend_toflagsgio.FILE_CREATE_NONEcancellableNoneappend_to_asynccallbackflagsgio.FILE_CREATE_NONEio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNoneappend_to_finishresultcopydestinationprogress_callbackflagsgio.FILE_COPY_NONEcancellableNoneuser_dataNonecopy_asyncdestinationcallbackflagsgio.FILE_CREATE_NONEio_priorityglib.PRIORITY_DEFAULTuser_dataNonecancellableNoneprogress_callbackNoneprogress_callback_dataNonecopy_attributesdestinationflagsgio.FILE_COPY_NONEcancellableNonecopy_finishresultcreateflagsgio.FILE_CREATE_NONEcancellableNonecreate_asynccallbackflagsgio.FILE_CREATE_NONEio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNonecreate_finishresultdeletecancellableNonedupeject_mountablecallbackflagsgio.FILE_CREATE_NONEcancellableNoneuser_dataNoneeject_mountable_finishresultenumerate_childrenattributesflagsgio.FILE_QUERY_INFO_NONEcancellableNoneenumerate_children_asyncattributescallbackflagsgio.FILE_QUERY_INFO_NONEio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNoneenumerate_children_finishresultequalfile2find_enclosing_mountcancellablefind_enclosing_mount_asynccallbackio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNonefind_enclosing_mount_finishresultget_basenameget_childget_child_for_display_nameget_parentget_parse_nameget_pathget_relative_pathdescendantget_uriget_uri_schemehas_prefixprefixhas_uri_schemeuri_schemeis_nativeload_contentscancellableload_contents_asynccallbackcancellableNoneuser_dataNoneload_contents_finishresultmake_directorycancellablemake_directory_with_parentscancellablemake_symbolic_linksymlink_valuecancellablemonitorflagscancellablemonitor_directoryflagscancellablemonitor_fileflagscancellablemount_enclosing_volumemount_operationcallbackflagsgio.MOUNT_MOUNT_NONEcancellableNoneuser_dataNonemount_enclosing_volume_finishresultmount_mountablemount_operationcallbackflagsgio.MOUNT_MOUNT_NONEcancellableNoneuser_dataNonemount_mountable_finishresultmovedestinationprogress_callbackflagsgio.FILE_COPY_NONEcancellableNoneuser_dataNonequery_default_handlercancellablequery_existscancellablequery_file_typeflagscancellablequery_filesystem_infoattributescancellablequery_filesystem_info_asyncattributescallbackio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNonequery_filesystem_info_finishresultquery_infoattributesflagscancellablequery_info_asynccallbackattributesflagsgio.FILE_QUERY_INFO_NONEio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNonequery_info_finishresultquery_settable_attributescancellableNonequery_writable_namespacecancellableNonereadcancellableNoneread_asynccallbackio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNoneread_finishresultNonereplaceetagmake_backupflagsgio.FILE_CREATE_NONEcancellableNonereplace_asynccallbacketagNonemake_backupTrueflagsgio.FILE_CREATE_NONEio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNonereplace_contentscontentsetagNonemake_backupTrueflagsgio.FILE_CREATE_NONEcancellableNonereplace_contents_asynccontentscallbacketagNonemake_backupTrueflagsgio.FILE_CREATE_NONEcancellableNoneuser_dataNonereplace_contents_finishresultNonereplace_finishresultNoneresolve_relative_pathrelative_pathset_attributeattributetypevalue_pflagsgio.FILE_QUERY_INFO_NONEcancellableNoneset_attribute_byte_stringattributevalueflagsgio.FILE_QUERY_INFO_NONEcancellableNoneset_attribute_int32attributevalueflagsgio.FILE_QUERY_INFO_NONEcancellableNoneset_attribute_int64attributevalueflagsgio.FILE_QUERY_INFO_NONEcancellableNoneset_attribute_stringattributevalueflagsgio.FILE_QUERY_INFO_NONEcancellableNoneset_attribute_uint32attributevalueflagsgio.FILE_QUERY_INFO_NONEcancellableNoneset_attribute_uint64attributevalueflagsgio.FILE_QUERY_INFO_NONEcancellableNoneset_attributes_asyncinfocallbackflagsgio.FILE_QUERY_INFO_NONEio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNoneset_attributes_finishresultset_attributes_from_infoinfoflagsgio.FILE_QUERY_INFO_NONEcancellableNoneset_dispay_namedisplay_namecancellableNoneset_display_name_asyncdisplay_namecallbackio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNoneset_display_name_finishresulttrashcancellableNoneunmount_mountablecallbackflagsgio.MOUNT_UNMOUNT_NONEcancellableNoneuser_dataNoneunmount_mountable_finishcancellableNoneFunctionsgio.file_parse_nameparse_nameAncestry+-- gobject.GInterface
+-- gio.File
Prerequisitesgio.File is implemented by
gobject.GObjectDescriptiongio.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.
Methodsgio.File.append_toappend_toflagsgio.FILE_CREATE_NONEcancellableNoneflags :a set of
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_asyncappend_to_asynccallbackflagsgio.FILE_CREATE_NONEio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNonecallback :a GAsyncReadyCallback to call when the request is satisfied.
flags :a set of
.
io_priority :the
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.Volume.append_to_finishappend_to_finishresultresult :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.copycopydestinationprogress_callbackflagsgio.FILE_COPY_NONEcancellableNoneuser_dataNonedestination :destination gio.File.
progress_callback :function to callback with progress information.
flags :a set of
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_asyncappend_to_asyncdestinationcallbackflagsgio.FILE_CREATE_NONEio_priorityglib.PRIORITY_DEFAULTuser_dataNonecancellableNoneprogress_callbackNoneprogress_callback_dataNonedestination :destination gio.File.
callback :a GAsyncReadyCallback to call when the request is satisfied.
flags :a set of
.
io_priority :the
of the request.
user_data :the data to pass to callback function.
cancellable :optional
gio.Cancellable
object, None to ignore.progress_callback :function to callback with progress information.
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_attributescopy_attributesdestinationflagsgio.FILE_COPY_NONEcancellableNonedestination :destination gio.File
to copy attributes to.
flags :a set of
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.Volume.copy_finishcopy_finishresultresult :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.createcreateflagsgio.FILE_CREATE_NONEcancellableNoneflags :a set of
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_asynccreate_asynccallbackflagsgio.FILE_CREATE_NONEio_priorityglib.PRIORITY_DEFAULTcancellableNoneuser_dataNonecallback :a GAsyncReadyCallback to call when the request is satisfied.
flags :a set of
.
io_priority :the
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.Volume.create_finishcreate_finishresultresult :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.Volume.deletedeletecancellablecancellable :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.Volume.dupdupReturns :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.