Gio.File¶
- Implementations:
None
Methods¶
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
None
Signals¶
None
Fields¶
None
Class Details¶
- class Gio.File¶
- Bases:
- Structure:
GFile
is a high level abstraction for manipulating files on a virtual file system.GFile``s are lightweight, immutable objects that do no I/O upon creation. It is necessary to understand that ``GFile
objects do not represent files, merely an identifier for a file. All file content I/O is implemented as streaming operations (see [class`Gio`.InputStream] and [class`Gio`.OutputStream]).To construct a
GFile
, you can use:[func`Gio`.File.new_for_path] if you have a path.
[func`Gio`.File.new_for_uri] if you have a URI.
[func`Gio`.File.new_for_commandline_arg] or [func`Gio`.File.new_for_commandline_arg_and_cwd] for a command line argument.
[func`Gio`.File.new_tmp] to create a temporary file from a template.
[func`Gio`.File.new_tmp_async] to asynchronously create a temporary file.
[func`Gio`.File.new_tmp_dir_async] to asynchronously create a temporary directory.
[func`Gio`.File.parse_name] from a UTF-8 string gotten from [method`Gio`.File.get_parse_name].
[func`Gio`.File.new_build_filename] or [func`Gio`.File.new_build_filenamev] to create a file from path elements.
One way to think of a
GFile
is as an abstraction of a pathname. For normal files the system pathname is what is stored internally, but as ``GFile``s are extensible it could also be something else that corresponds to a pathname in a userspace implementation of a filesystem.GFile``s make up hierarchies of directories and files that correspond to the files on a filesystem. You can move through the file system with ``GFile
using [method`Gio`.File.get_parent] to get an identifier for the parent directory, [method`Gio`.File.get_child] to get a child within a directory, and [method`Gio`.File.resolve_relative_path] to resolve a relative path between two ``GFile``s. There can be multiple hierarchies, so you may not end up at the same root if you repeatedly call [method`Gio`.File.get_parent] on two different files.All
GFile``s have a basename (get with [method`Gio`.File.get\_basename]). These names are byte strings that are used to identify the file on the filesystem (relative to its parent directory) and there is no guarantees that they have any particular charset encoding or even make any sense at all. If you want to use filenames in a user interface you should use the display name that you can get by requesting the ``G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
attribute with [method`Gio`.File.query_info]. This is guaranteed to be in UTF-8 and can be used in a user interface. But always store the real basename or theGFile
to use to actually access the file, because there is no way to go from a display name to the actual name.Using
GFile
as an identifier has the same weaknesses as using a path in that there may be multiple aliases for the same file. For instance, hard or soft links may cause two differentGFile``s to refer to the same file. Other possible causes for aliases are\: case insensitive filesystems, short and long names on FAT/NTFS, or bind mounts in Linux. If you want to check if two ``GFile``s point to the same file you can query for the ``G_FILE_ATTRIBUTE_ID_FILE
attribute. Note thatGFile
does some trivial canonicalization of pathnames passed in, so that trivial differences in the path string used at creation (duplicated slashes, slash at end of path,.
or..
path segments, etc) does not create different ``GFile``s.Many
GFile
operations have both synchronous and asynchronous versions to suit your application. Asynchronous versions of synchronous functions simply have_async()
appended to their function names. The asynchronous I/O functions call a [callback`Gio`.AsyncReadyCallback] which is then used to finalize the operation, producing a [iface`Gio`.AsyncResult] which is then passed to the function’s matching_finish()
operation.It is highly recommended to use asynchronous calls when running within a shared main loop, such as in the main thread of an application. This avoids I/O operations blocking other sources on the main loop from being dispatched. Synchronous I/O operations should be performed from worker threads. See the introduction to asynchronous programming section for more.
Some
GFile
operations almost always take a noticeable amount of time, and so do not have synchronous analogs. Notable cases include:[method`Gio`.File.mount_mountable] to mount a mountable file.
[method`Gio`.File.unmount_mountable_with_operation] to unmount a mountable file.
[method`Gio`.File.eject_mountable_with_operation] to eject a mountable file.
- Entity Tags
One notable feature of
GFile``s are entity tags, or ‘etags’ for short. Entity tags are somewhat like a more abstract version of the traditional mtime, and can be used to quickly determine if the file has been modified from the version on the file system. See the HTTP 1.1 `specification <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>`__ for HTTP ``ETag
headers, which are a very similar concept.- classmethod new_build_filenamev(args)[source]¶
- Parameters:
args ([
str
]) –None
-terminated array of strings containing the path elements.- Returns:
a new
Gio.File
- Return type:
Constructs a
Gio.File
from a vector of elements using the correct separator for filenames.Using this function is equivalent to calling
GLib.build_filenamev
(), followed byGio.File.new_for_path
() on the result.New in version 2.78.
- classmethod new_for_commandline_arg(arg)[source]¶
- Parameters:
arg (
str
) – a command line string- Returns:
a new
Gio.File
. Free the returned object withGObject.Object.unref
().- Return type:
Creates a
Gio.File
with the given argument from the command line. The value of arg can be either a URI, an absolute path or a relative path resolved relative to the current working directory. This operation never fails, but the returned object might not support any I/O operation if arg points to a malformed path.Note that on Windows, this function expects its argument to be in UTF-8 – not the system code page. This means that you should not use this function with string from argv as it is passed to main(). g_win32_get_command_line() will return a UTF-8 version of the commandline.
Gio.Application
also uses UTF-8 butGio.ApplicationCommandLine.create_file_for_arg
() may be more useful for you there. It is also always possible to use this function withGLib.OptionContext
arguments of typeGLib.OptionArg.FILENAME
.
- classmethod new_for_commandline_arg_and_cwd(arg, cwd)[source]¶
- Parameters:
- Returns:
a new
Gio.File
- Return type:
Creates a
Gio.File
with the given argument from the command line.This function is similar to
Gio.File.new_for_commandline_arg
() except that it allows for passing the current working directory as an argument instead of using the current working directory of the process.This is useful if the commandline argument was given in a context other than the invocation of the current process.
See also
Gio.ApplicationCommandLine.create_file_for_arg
().New in version 2.36.
- classmethod new_for_path(path)[source]¶
- Parameters:
path (
str
) – a string containing a relative or absolute path. The string must be encoded in the glib filename encoding.- Returns:
a new
Gio.File
for the given path. Free the returned object withGObject.Object.unref
().- Return type:
Constructs a
Gio.File
for a given path. This operation never fails, but the returned object might not support any I/O operation if path is malformed.
- classmethod new_for_uri(uri)[source]¶
- Parameters:
uri (
str
) – a UTF-8 string containing a URI- Returns:
a new
Gio.File
for the given uri. Free the returned object withGObject.Object.unref
().- Return type:
Constructs a
Gio.File
for a given URI. This operation never fails, but the returned object might not support any I/O operation if uri is malformed or if the uri type is not supported.
- classmethod new_tmp(tmpl)[source]¶
- Parameters:
tmpl (
str
orNone
) – Template for the file name, as inGLib.file_open_tmp
(), orNone
for a default template- Raises:
- Returns:
a new
Gio.File
. Free the returned object withGObject.Object.unref
().- iostream:
on return, a
Gio.FileIOStream
for the created file
- Return type:
(
Gio.File
, iostream:Gio.FileIOStream
)
Opens a file in the preferred directory for temporary files (as returned by
GLib.get_tmp_dir
()) and returns aGio.File
andGio.FileIOStream
pointing to it.tmpl should be a string in the GLib file name encoding containing a sequence of six ‘X’ characters, and containing no directory components. If it is
None
, a default template is used.Unlike the other
Gio.File
constructors, this will returnNone
if a temporary file could not be created.New in version 2.32.
- classmethod new_tmp_async(tmpl, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
tmpl (
str
orNone
) – Template for the file name, as inGLib.file_open_tmp
(), orNone
for a default templateio_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is done
Asynchronously opens a file in the preferred directory for temporary files (as returned by
GLib.get_tmp_dir
()) asGio.File.new_tmp
().tmpl should be a string in the GLib file name encoding containing a sequence of six ‘X’ characters, and containing no directory components. If it is
None
, a default template is used.New in version 2.74.
- classmethod new_tmp_dir_async(tmpl, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
tmpl (
str
orNone
) – Template for the file name, as inGLib.Dir.make_tmp
(), orNone
for a default templateio_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is done
Asynchronously creates a directory in the preferred directory for temporary files (as returned by
GLib.get_tmp_dir
()) asGLib.Dir.make_tmp
().tmpl should be a string in the GLib file name encoding containing a sequence of six ‘X’ characters, and containing no directory components. If it is
None
, a default template is used.New in version 2.74.
- classmethod new_tmp_dir_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a new
Gio.File
. Free the returned object withGObject.Object.unref
().- Return type:
Finishes a temporary directory creation started by
Gio.File.new_tmp_dir_async
().New in version 2.74.
- classmethod new_tmp_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a new
Gio.File
. Free the returned object withGObject.Object.unref
().- iostream:
on return, a
Gio.FileIOStream
for the created file
- Return type:
(
Gio.File
, iostream:Gio.FileIOStream
)
Finishes a temporary file creation started by
Gio.File.new_tmp_async
().New in version 2.74.
- classmethod parse_name(parse_name)[source]¶
- Parameters:
parse_name (
str
) – a file name or path to be parsed- Returns:
a new
Gio.File
.- Return type:
Constructs a
Gio.File
with the given parse_name (i.e. something given byGio.File.get_parse_name
()). This operation never fails, but the returned object might not support any I/O operation if the parse_name cannot be parsed.
- append_to(flags, cancellable)[source]¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.FileOutputStream
, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Gets an output stream for appending data to the file. If the file doesn’t already exist it is created.
By default files created are generally readable by everyone, but if you pass
Gio.FileCreateFlags.PRIVATE
in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.Some file systems don’t allow all file names, and may return an
Gio.IOErrorEnum.INVALID_FILENAME
error. If the file is a directory theGio.IOErrorEnum.IS_DIRECTORY
error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- append_to_async(flags, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously opens self for appending.
For more details, see
Gio.File.append_to
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.append_to_finish
() to get the result of the operation.
- append_to_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) –Gio.AsyncResult
- Raises:
- Returns:
a valid
Gio.FileOutputStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file append operation started with
Gio.File.append_to_async
().
- build_attribute_list_for_copy(flags, cancellable)[source]¶
- Parameters:
flags (
Gio.FileCopyFlags
) – a set ofGio.FileCopyFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
an attribute query string for
Gio.File.query_info
(), orNone
if an error occurs.- Return type:
Prepares the file attribute query string for copying to self.
This function prepares an attribute query string to be passed to
Gio.File.query_info
() to get a list of attributes normally copied with the file (seeGio.File.copy_attributes
() for the detailed description). This function is used by the implementation ofGio.File.copy_attributes
() and is useful when one needs to query and set the attributes in two stages (e.g., for recursive move of a directory).New in version 2.68.
- copy(destination, flags, cancellable, progress_callback, *progress_callback_data)[source]¶
- Parameters:
flags (
Gio.FileCopyFlags
) – set ofGio.FileCopyFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignoreprogress_callback (
Gio.FileProgressCallback
orNone
) – function to callback with progress information, orNone
if progress information is not neededprogress_callback_data (
object
orNone
) – user data to pass to progress_callback
- Raises:
- Returns:
- Return type:
Copies the file self to the location specified by destination. Can not handle recursive copies of directories.
If the flag
Gio.FileCopyFlags.OVERWRITE
is specified an already existing destination file is overwritten.If the flag
Gio.FileCopyFlags.NOFOLLOW_SYMLINKS
is specified then symlinks will be copied as symlinks, otherwise the target of the self symlink will be copied.If the flag
Gio.FileCopyFlags.ALL_METADATA
is specified then all the metadata that is possible to copy is copied, not just the default subset (which, for instance, does not include the owner, seeGio.FileInfo
).If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If progress_callback is not
None
, then the operation can be monitored by setting this to aGio.FileProgressCallback
function. progress_callback_data will be passed to this function. It is guaranteed that this callback will be called after all data has been transferred with the total number of bytes copied during the operation.If the self file does not exist, then the
Gio.IOErrorEnum.NOT_FOUND
error is returned, independent on the status of the destination.If
Gio.FileCopyFlags.OVERWRITE
is not specified and the target exists, then the errorGio.IOErrorEnum.EXISTS
is returned.If trying to overwrite a file over a directory, the
Gio.IOErrorEnum.IS_DIRECTORY
error is returned. If trying to overwrite a directory with a directory theGio.IOErrorEnum.WOULD_MERGE
error is returned.If the source is a directory and the target does not exist, or
Gio.FileCopyFlags.OVERWRITE
is specified and the target is a file, then theGio.IOErrorEnum.WOULD_RECURSE
error is returned.If you are interested in copying the
Gio.File
object itself (not the on-disk file), seeGio.File.dup
().
- copy_async(destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.FileCopyFlags
) – set ofGio.FileCopyFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignoreprogress_callback (
Gio.FileProgressCallback
orNone
) – function to callback with progress information, orNone
if progress information is not neededprogress_callback_data (
object
orNone
) – user data to pass to progress_callbackcallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied
Copies the file self to the location specified by destination asynchronously. For details of the behaviour, see
Gio.File.copy
().If progress_callback is not
None
, then that function that will be called just like inGio.File.copy
(). The callback will run in the default main context of the thread callingGio.File.copy_async
() — the same context as callback is run in.When the operation is finished, callback will be called. You can then call
Gio.File.copy_finish
() to get the result of the operation.
- copy_attributes(destination, flags, cancellable)[source]¶
- Parameters:
flags (
Gio.FileCopyFlags
) – a set ofGio.FileCopyFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
True
if the attributes were copied successfully,False
otherwise.- Return type:
Copies the file attributes from self to destination.
Normally only a subset of the file attributes are copied, those that are copies in a normal file copy operation (which for instance does not include e.g. owner). However if
Gio.FileCopyFlags.ALL_METADATA
is specified in flags, then all the metadata that is possible to copy is copied. This is useful when implementing move by copy + delete source.
- copy_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
- Return type:
Finishes copying the file started with
Gio.File.copy_async
().
- create(flags, cancellable)[source]¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.FileOutputStream
for the newly created file, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Creates a new file and returns an output stream for writing to it. The file must not already exist.
By default files created are generally readable by everyone, but if you pass
Gio.FileCreateFlags.PRIVATE
in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If a file or directory with this name already exists the
Gio.IOErrorEnum.EXISTS
error will be returned. Some file systems don’t allow all file names, and may return anGio.IOErrorEnum.INVALID_FILENAME
error, and if the name is to longGio.IOErrorEnum.FILENAME_TOO_LONG
will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- create_async(flags, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously creates a new file and returns an output stream for writing to it. The file must not already exist.
For more details, see
Gio.File.create
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.create_finish
() to get the result of the operation.
- create_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a
Gio.FileOutputStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file create operation started with
Gio.File.create_async
().
- create_readwrite(flags, cancellable)[source]¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.FileIOStream
for the newly created file, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Creates a new file and returns a stream for reading and writing to it. The file must not already exist.
By default files created are generally readable by everyone, but if you pass
Gio.FileCreateFlags.PRIVATE
in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If a file or directory with this name already exists, the
Gio.IOErrorEnum.EXISTS
error will be returned. Some file systems don’t allow all file names, and may return anGio.IOErrorEnum.INVALID_FILENAME
error, and if the name is too long,Gio.IOErrorEnum.FILENAME_TOO_LONG
will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.
New in version 2.22.
- create_readwrite_async(flags, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously creates a new file and returns a stream for reading and writing to it. The file must not already exist.
For more details, see
Gio.File.create_readwrite
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.create_readwrite_finish
() to get the result of the operation.New in version 2.22.
- create_readwrite_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a
Gio.FileIOStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file create operation started with
Gio.File.create_readwrite_async
().New in version 2.22.
- delete(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Raises:
- Returns:
- Return type:
Deletes a file. If the self is a directory, it will only be deleted if it is empty. This has the same semantics as
GLib.unlink
().If self doesn’t exist,
Gio.IOErrorEnum.NOT_FOUND
will be returned. This allows for deletion to be implemented avoiding time-of-check to time-of-use races :g_autoptr(GError) local_error = NULL; if (!g_file_delete (my_file, my_cancellable, &local_error) && !g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { // deletion failed for some reason other than the file not existing: // so report the error g_warning ("Failed to delete %s: %s", g_file_peek_path (my_file), local_error->message); }
If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- delete_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously delete a file. If the self is a directory, it will only be deleted if it is empty. This has the same semantics as
GLib.unlink
().New in version 2.34.
- delete_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
- Return type:
Finishes deleting a file started with
Gio.File.delete_async
().New in version 2.34.
- dup()[source]¶
-
Duplicates a
Gio.File
handle. This operation does not duplicate the actual file or directory represented by theGio.File
; seeGio.File.copy
() if attempting to copy a file.Gio.File.dup
() is useful when a second handle is needed to the same underlying file, for use in a separate thread (Gio.File
is not thread-safe). For use within the same thread, useGObject.Object.ref
() to increment the existing object’s reference count.This call does no blocking I/O.
- eject_mountable(flags, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.MountUnmountFlags
) – flags affecting the operationcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
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 errorGio.IOErrorEnum.CANCELLED
will be returned.Deprecated since version 2.22: Use
Gio.File.eject_mountable_with_operation
() instead.
- eject_mountable_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
- Return type:
Finishes an asynchronous eject operation started by
Gio.File.eject_mountable
().Deprecated since version 2.22: Use
Gio.File.eject_mountable_with_operation_finish
() instead.
- eject_mountable_with_operation(flags, mount_operation, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.MountUnmountFlags
) – flags affecting the operationmount_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
, orNone
to avoid user interactioncancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Starts an asynchronous eject on a mountable. When this operation has completed, callback will be called with user_user data, and the operation can be finalized with
Gio.File.eject_mountable_with_operation_finish
().If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.New in version 2.22.
- eject_mountable_with_operation_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
- Return type:
Finishes an asynchronous eject operation started by
Gio.File.eject_mountable_with_operation
().New in version 2.22.
- enumerate_children(attributes, flags, cancellable)[source]¶
- Parameters:
attributes (
str
) – an attribute query stringflags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
A
Gio.FileEnumerator
if successful,None
on error. Free the returned object withGObject.Object.unref
().- Return type:
Gets the requested information about the files in a directory. The result is a
Gio.FileEnumerator
object that will give outGio.FileInfo
objects for all the files in the directory.The attributes value is a string that specifies the file attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “standard::*” means all attributes in the standard namespace. An example attribute query be “standard::*,owner::user”. The standard attributes are available as defines, like
Gio.FILE_ATTRIBUTE_STANDARD_NAME
.Gio.FILE_ATTRIBUTE_STANDARD_NAME
should always be specified if you plan to callGio.FileEnumerator.get_child
() orGio.FileEnumerator.iterate
() on the returned enumerator.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If the file does not exist, the
Gio.IOErrorEnum.NOT_FOUND
error will be returned. If the file is not a directory, theGio.IOErrorEnum.NOT_DIRECTORY
error will be returned. Other errors are possible too.
- enumerate_children_async(attributes, flags, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
attributes (
str
) – an attribute query stringflags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously gets the requested information about the files in a directory. The result is a
Gio.FileEnumerator
object that will give outGio.FileInfo
objects for all the files in the directory.For more details, see
Gio.File.enumerate_children
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.enumerate_children_finish
() to get the result of the operation.
- enumerate_children_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a
Gio.FileEnumerator
orNone
if an error occurred. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an async enumerate children operation. See
Gio.File.enumerate_children_async
().
- equal(file2)[source]¶
- Parameters:
- Returns:
True
if self and file2 are equal.- Return type:
Checks if the two given
Gio.Files
refer to the same file.Note that two
Gio.Files
that differ can still refer to the same file on the filesystem due to various forms of filename aliasing.This call does no blocking I/O.
- find_enclosing_mount(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Raises:
- Returns:
a
Gio.Mount
where the self is located orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Gets a
Gio.Mount
for theGio.File
.Gio.Mount
is returned only for user interesting locations, seeGio.VolumeMonitor
. If theGio.FileIface
for self does not have a #mount, error will be set toGio.IOErrorEnum.NOT_FOUND
andNone
#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 errorGio.IOErrorEnum.CANCELLED
will be returned.
- find_enclosing_mount_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously gets the mount for the file.
For more details, see
Gio.File.find_enclosing_mount
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.find_enclosing_mount_finish
() to get the result of the operation.
- find_enclosing_mount_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
Gio.Mount
for given self orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous find mount request. See
Gio.File.find_enclosing_mount_async
().
- get_basename()[source]¶
- Returns:
string containing the
Gio.File
's base name, orNone
if givenGio.File
is invalid. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
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 withGio.File.query_info
().This call does no blocking I/O.
- get_child(name)[source]¶
- Parameters:
name (
str
) – string containing the child’s basename- Returns:
a
Gio.File
to a child specified by name. Free the returned object withGObject.Object.unref
().- Return type:
Gets a child of self with basename equal to name.
Note that the file with that specific name might not exist, but you can still have a
Gio.File
that points to it. You can use this for instance to create that file.This call does no blocking I/O.
- get_child_for_display_name(display_name)[source]¶
- Parameters:
display_name (
str
) – string to a possible child- Raises:
- Returns:
a
Gio.File
to the specified child, orNone
if the display name couldn’t be converted. Free the returned object withGObject.Object.unref
().- Return type:
Gets the child of self for a given display_name (i.e. a UTF-8 version of the name). If this function fails, it returns
None
and error will be set. This is very useful when constructing aGio.File
for a new file and the user entered the filename in the user interface, for instance when you select a directory and type a filename in the file selector.This call does no blocking I/O.
- get_parent()[source]¶
- Returns:
a
Gio.File
structure to the parent of the givenGio.File
orNone
if there is no parent. Free the returned object withGObject.Object.unref
().- Return type:
Gets the parent directory for the self. If the self represents the root directory of the file system, then
None
will be returned.This call does no blocking I/O.
- get_parse_name()[source]¶
- Returns:
a string containing the
Gio.File
's parse name. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
Gets the parse name of the self. A parse name is a UTF-8 string that describes the file such that one can get the
Gio.File
back usingGio.File.parse_name
().This is generally used to show the
Gio.File
as a nice full-pathname kind of string in a user interface, like in a location entry.For local files with names that can safely be converted to UTF-8 the pathname is used, otherwise the IRI is used (a form of URI that allows UTF-8 characters unescaped).
This call does no blocking I/O.
- get_path()[source]¶
- Returns:
string containing the
Gio.File
's path, orNone
if no such path exists. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
Gets the local pathname for
Gio.File
, if one exists. If non-None
, this is guaranteed to be an absolute, canonical path. It might contain symlinks.This call does no blocking I/O.
- get_relative_path(descendant)[source]¶
- Parameters:
- Returns:
string with the relative path from descendant to self, or
None
if descendant doesn’t have self as prefix. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
Gets the path for descendant relative to self.
This call does no blocking I/O.
- get_uri()[source]¶
- Returns:
a string containing the
Gio.File
's URI. If theGio.File
was constructed with an invalid URI, an invalid URI is returned. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
Gets the URI for the self.
This call does no blocking I/O.
- get_uri_scheme()[source]¶
- Returns:
a string containing the URI scheme for the given
Gio.File
orNone
if theGio.File
was constructed with an invalid URI. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
Gets the URI scheme for a
Gio.File
. RFC 3986 decodes the scheme as:URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
Common schemes include “file”, “http”, “ftp”, etc.
The scheme can be different from the one used to construct the
Gio.File
, in that it might be replaced with one that is logically equivalent to theGio.File
.This call does no blocking I/O.
- has_parent(parent)[source]¶
- Parameters:
parent (
Gio.File
orNone
) – the parent to check for, orNone
- Returns:
True
if self is an immediate child of parent (or any parent in the case that parent isNone
).- Return type:
Checks if self has a parent, and optionally, if it is parent.
If parent is
None
then this function returnsTrue
if self has any parent at all. If parent is non-None
thenTrue
is only returned if self is an immediate child of parent.New in version 2.24.
- has_prefix(prefix)[source]¶
- Parameters:
- Returns:
True
if the self's parent, grandparent, etc is prefix,False
otherwise.- Return type:
Checks whether self has the prefix specified by prefix.
In other words, if the names of initial elements of self's pathname match prefix. Only full pathname elements are matched, so a path like /foo is not considered a prefix of /foobar, only of /foo/bar.
A
Gio.File
is not a prefix of itself. If you want to check for equality, useGio.File.equal
().This call does no I/O, as it works purely on names. As such it can sometimes return
False
even if self is inside a prefix (from a filesystem point of view), because the prefix of self is an alias of prefix.
- has_uri_scheme(uri_scheme)[source]¶
- Parameters:
uri_scheme (
str
) – a string containing a URI scheme- Returns:
True
ifGio.File
's backend supports the given URI scheme,False
if URI scheme isNone
, not supported, orGio.File
is invalid.- Return type:
Checks to see if a
Gio.File
has a given URI scheme.This call does no blocking I/O.
- hash()[source]¶
- Returns:
0 if self is not a valid
Gio.File
, otherwise an integer that can be used as hash value for theGio.File
. This function is intended for easily hashing aGio.File
to add to aGLib.HashTable
or similar data structure.- Return type:
Creates a hash value for a
Gio.File
.This call does no blocking I/O.
- is_native()[source]¶
-
Checks to see if a file is native to the platform.
A native file is one expressed in the platform-native filename format, e.g. “C:\Windows” or “/usr/bin/”. This does not mean the file is local, as it might be on a locally mounted remote filesystem.
On some systems non-native files may be available using the native filesystem via a userspace filesystem (FUSE), in these cases this call will return
False
, butGio.File.get_path
() will still return a native path.This call does no blocking I/O.
- load_bytes(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
- Raises:
- Returns:
a
GLib.Bytes
orNone
and error is set- etag_out:
a location to place the current entity tag for the file, or
None
if the entity tag is not needed
- Return type:
(
GLib.Bytes
, etag_out:str
orNone
)
Loads the contents of self and returns it as
GLib.Bytes
.If self is a resource:// based URI, the resulting bytes will reference the embedded resource instead of a copy. Otherwise, this is equivalent to calling
Gio.File.load_contents
() andGLib.Bytes.new_take
().For resources, etag_out will be set to
None
.The data contained in the resulting
GLib.Bytes
is always zero-terminated, but this is not included in theGLib.Bytes
length. The resultingGLib.Bytes
should be freed withGLib.Bytes.unref
() when no longer in use.New in version 2.56.
- load_bytes_async(cancellable, callback, *user_data)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
orNone
callback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously loads the contents of self as
GLib.Bytes
.If self is a resource:// based URI, the resulting bytes will reference the embedded resource instead of a copy. Otherwise, this is equivalent to calling
Gio.File.load_contents_async
() andGLib.Bytes.new_take
().callback should call
Gio.File.load_bytes_finish
() to get the result of this asynchronous operation.See
Gio.File.load_bytes
() for more information.New in version 2.56.
- load_bytes_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
provided to the callback- Raises:
- Returns:
a
GLib.Bytes
orNone
and error is set- etag_out:
a location to place the current entity tag for the file, or
None
if the entity tag is not needed
- Return type:
(
GLib.Bytes
, etag_out:str
orNone
)
Completes an asynchronous request to
Gio.File.load_bytes_async
().For resources, etag_out will be set to
None
.The data contained in the resulting
GLib.Bytes
is always zero-terminated, but this is not included in theGLib.Bytes
length. The resultingGLib.Bytes
should be freed withGLib.Bytes.unref
() when no longer in use.See
Gio.File.load_bytes
() for more information.New in version 2.56.
- load_contents(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Raises:
- Returns:
True
if the self's contents were successfully loaded.False
if there were errors.- contents:
a location to place the contents of the file
- etag_out:
a location to place the current entity tag for the file, or
None
if the entity tag is not needed
- Return type:
Loads the content of the file into memory. The data is always zero-terminated, but this is not included in the resultant length. The returned contents should be freed with
GLib.free
() when no longer needed.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- load_contents_async(cancellable, callback, *user_data)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Starts an asynchronous load of the self's contents.
For more details, see
Gio.File.load_contents
() which is the synchronous version of this call.When the load operation has completed, callback will be called with user data. To finish the operation, call
Gio.File.load_contents_finish
() with theGio.AsyncResult
returned by the callback.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- load_contents_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
True
if the load was successful. IfFalse
and error is present, it will be set appropriately.- contents:
a location to place the contents of the file
- etag_out:
a location to place the current entity tag for the file, or
None
if the entity tag is not needed
- Return type:
Finishes an asynchronous load of the self's contents. The contents are placed in contents, and length is set to the size of the contents string. The contents should be freed with
GLib.free
() when no longer needed. If etag_out is present, it will be set to the new entity tag for the self.
- load_partial_contents_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
True
if the load was successful. IfFalse
and error is present, it will be set appropriately.- contents:
a location to place the contents of the file
- etag_out:
a location to place the current entity tag for the file, or
None
if the entity tag is not needed
- Return type:
Finishes an asynchronous partial load operation that was started with g_file_load_partial_contents_async(). The data is always zero-terminated, but this is not included in the resultant length. The returned contents should be freed with
GLib.free
() when no longer needed.
- make_directory(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Raises:
- Returns:
- Return type:
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, seeGio.File.make_directory_with_parents
(). This function will fail if the parent directory does not exist, setting error toGio.IOErrorEnum.NOT_FOUND
. If the file system doesn’t support creating directories, this function will fail, setting error toGio.IOErrorEnum.NOT_SUPPORTED
.For a local
Gio.File
the newly created directory will have the default (current) ownership and permissions of the current process.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- make_directory_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously creates a directory.
New in version 2.38.
- make_directory_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
- Return type:
Finishes an asynchronous directory creation, started with
Gio.File.make_directory_async
().New in version 2.38.
- make_directory_with_parents(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Raises:
- Returns:
True
if all directories have been successfully created,False
otherwise.- Return type:
Creates a directory and any parent directories that may not exist similar to ‘mkdir -p’. If the file system does not support creating directories, this function will fail, setting error to
Gio.IOErrorEnum.NOT_SUPPORTED
. If the directory itself already exists, this function will fail setting error toGio.IOErrorEnum.EXISTS
, unlike the similarGLib.mkdir_with_parents
().For a local
Gio.File
the newly created directories will have the default (current) ownership and permissions of the current process.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.New in version 2.18.
- make_symbolic_link(symlink_value, cancellable)[source]¶
- Parameters:
symlink_value (
str
) – a string with the path for the target of the new symlinkcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
- Return type:
Creates a symbolic link named self which contains the string symlink_value.
If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- make_symbolic_link_async(symlink_value, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
symlink_value (
str
) – a string with the path for the target of the new symlinkio_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously creates a symbolic link named self which contains the string symlink_value.
New in version 2.74.
- make_symbolic_link_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
- Return type:
Finishes an asynchronous symbolic link creation, started with
Gio.File.make_symbolic_link_async
().New in version 2.74.
- measure_disk_usage(flags, cancellable, progress_callback, *progress_data)[source]¶
- Parameters:
flags (
Gio.FileMeasureFlags
) –Gio.FileMeasureFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
progress_callback (
Gio.FileMeasureProgressCallback
orNone
) – aGio.FileMeasureProgressCallback
progress_data (
object
orNone
) – user_data for progress_callback
- Raises:
- Returns:
True
if successful, with the out parameters set.False
otherwise, with error set.- disk_usage:
the number of bytes of disk space used
- num_dirs:
the number of directories encountered
- num_files:
the number of non-directories encountered
- Return type:
Recursively measures the disk usage of self.
This is essentially an analog of the ‘du’ command, but it also reports the number of directories and non-directory files encountered (including things like symbolic links).
By default, errors are only reported against the toplevel file itself. Errors found while recursing are silently ignored, unless
Gio.FileMeasureFlags.REPORT_ANY_ERROR
is given in flags.The returned size, disk_usage, is in bytes and should be formatted with
GLib.format_size
() in order to get something reasonable for showing in a user interface.progress_callback and progress_data can be given to request periodic progress updates while scanning. See the documentation for
Gio.FileMeasureProgressCallback
for information about when and how the callback will be invoked.New in version 2.38.
- measure_disk_usage_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – theGio.AsyncResult
passed to yourGio.AsyncReadyCallback
- Raises:
- Returns:
True
if successful, with the out parameters set.False
otherwise, with error set.- disk_usage:
the number of bytes of disk space used
- num_dirs:
the number of directories encountered
- num_files:
the number of non-directories encountered
- Return type:
Collects the results from an earlier call to g_file_measure_disk_usage_async(). See
Gio.File.measure_disk_usage
() for more information.New in version 2.38.
- monitor(flags, cancellable)[source]¶
- Parameters:
flags (
Gio.FileMonitorFlags
) – a set ofGio.FileMonitorFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.FileMonitor
for the given self, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.New in version 2.18.
- monitor_directory(flags, cancellable)[source]¶
- Parameters:
flags (
Gio.FileMonitorFlags
) – a set ofGio.FileMonitorFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.FileMonitor
for the given self, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.It does not make sense for flags to contain
Gio.FileMonitorFlags.WATCH_HARD_LINKS
, since hard links can not be made to directories. It is not possible to monitor all the files in a directory for changes made via hard links; if you want to do this then you must register individual watches withGio.File.monitor
().
- monitor_file(flags, cancellable)[source]¶
- Parameters:
flags (
Gio.FileMonitorFlags
) – a set ofGio.FileMonitorFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.FileMonitor
for the given self, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.If flags contains
Gio.FileMonitorFlags.WATCH_HARD_LINKS
then the monitor will also attempt to report changes made to the file via another filename (ie, a hard link). Without this flag, you can only rely on changes made through the filename contained in self to be reported. Using this flag may result in an increase in resource usage, and may not have any effect depending on theGio.FileMonitor
backend and/or filesystem type.
- mount_enclosing_volume(flags, mount_operation, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.MountMountFlags
) – flags affecting the operationmount_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
orNone
to avoid user interactioncancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied, orNone
user_data (
object
orNone
) – the data to pass to callback function
Starts a mount_operation, mounting the volume that contains the file self.
When this operation has completed, callback will be called with user_user data, and the operation can be finalized with
Gio.File.mount_enclosing_volume_finish
().If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- mount_enclosing_volume_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
True
if successful. If an error has occurred, this function will returnFalse
and set error appropriately if present.- Return type:
Finishes a mount operation started by
Gio.File.mount_enclosing_volume
().
- mount_mountable(flags, mount_operation, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.MountMountFlags
) – flags affecting the operationmount_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
, orNone
to avoid user interactioncancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Mounts a file of type
Gio.FileType.MOUNTABLE
. Using mount_operation, you can request callbacks when, for instance, passwords are needed during authentication.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.mount_mountable_finish
() to get the result of the operation.
- mount_mountable_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a
Gio.File
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes a mount operation. See
Gio.File.mount_mountable
() for details.Finish an asynchronous mount operation that was started with
Gio.File.mount_mountable
().
- move(destination, flags, cancellable, progress_callback, *progress_callback_data)[source]¶
- Parameters:
destination (
Gio.File
) –Gio.File
pointing to the destination locationflags (
Gio.FileCopyFlags
) – set ofGio.FileCopyFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignoreprogress_callback (
Gio.FileProgressCallback
orNone
) –Gio.FileProgressCallback
function for updatesprogress_callback_data (
object
orNone
) –object
to user data for the callback function
- Raises:
- Returns:
- Return type:
Tries to move the file or directory self to the location specified by destination. If native move operations are supported then this is used, otherwise a copy + delete fallback is used. The native implementation may support moving directories (for instance on moves inside the same filesystem), but the fallback code does not.
If the flag
Gio.FileCopyFlags.OVERWRITE
is specified an already existing destination file is overwritten.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If progress_callback is not
None
, then the operation can be monitored by setting this to aGio.FileProgressCallback
function. progress_callback_data will be passed to this function. It is guaranteed that this callback will be called after all data has been transferred with the total number of bytes copied during the operation.If the self file does not exist, then the
Gio.IOErrorEnum.NOT_FOUND
error is returned, independent on the status of the destination.If
Gio.FileCopyFlags.OVERWRITE
is not specified and the target exists, then the errorGio.IOErrorEnum.EXISTS
is returned.If trying to overwrite a file over a directory, the
Gio.IOErrorEnum.IS_DIRECTORY
error is returned. If trying to overwrite a directory with a directory theGio.IOErrorEnum.WOULD_MERGE
error is returned.If the source is a directory and the target does not exist, or
Gio.FileCopyFlags.OVERWRITE
is specified and the target is a file, then theGio.IOErrorEnum.WOULD_RECURSE
error may be returned (if the native move operation isn’t available).
- move_async(destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data)[source]¶
- Parameters:
destination (
Gio.File
) –Gio.File
pointing to the destination locationflags (
Gio.FileCopyFlags
) – set ofGio.FileCopyFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignoreprogress_callback (
Gio.FileProgressCallback
orNone
) –Gio.FileProgressCallback
function for updatesprogress_callback_data (
object
orNone
) –object
to user data for the callback functioncallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously moves a file self to the location of destination. For details of the behaviour, see
Gio.File.move
().If progress_callback is not
None
, then that function that will be called just like inGio.File.move
(). The callback will run in the default main context of the thread callingGio.File.move_async
() — the same context as callback is run in.When the operation is finished, callback will be called. You can then call
Gio.File.move_finish
() to get the result of the operation.New in version 2.72.
- move_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
- Return type:
Finishes an asynchronous file movement, started with
Gio.File.move_async
().New in version 2.72.
- open_readwrite(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
- Raises:
- Returns:
Gio.FileIOStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Opens an existing file for reading and writing. The result is a
Gio.FileIOStream
that can be used to read and write the contents of the file.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If the file does not exist, the
Gio.IOErrorEnum.NOT_FOUND
error will be returned. If the file is a directory, theGio.IOErrorEnum.IS_DIRECTORY
error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on. Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.New in version 2.22.
- open_readwrite_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously opens self for reading and writing.
For more details, see
Gio.File.open_readwrite
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.open_readwrite_finish
() to get the result of the operation.New in version 2.22.
- open_readwrite_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a
Gio.FileIOStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file read operation started with
Gio.File.open_readwrite_async
().New in version 2.22.
- peek_path()[source]¶
- Returns:
string containing the
Gio.File
's path, orNone
if no such path exists. The returned string is owned by self.- Return type:
Exactly like
Gio.File.get_path
(), but caches the result via g_object_set_qdata_full(). This is useful for example in C applications which mixg_file_*
APIs with native ones. It also avoids an extra duplicated string when possible, so will be generally more efficient.This call does no blocking I/O.
New in version 2.56.
- poll_mountable(cancellable, callback, *user_data)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied, orNone
user_data (
object
orNone
) – the data to pass to callback function
Polls a file of type
Gio.FileType.MOUNTABLE
.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.mount_mountable_finish
() to get the result of the operation.New in version 2.22.
- poll_mountable_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
True
if the operation finished successfully.False
otherwise.- Return type:
Finishes a poll operation. See
Gio.File.poll_mountable
() for details.Finish an asynchronous poll operation that was polled with
Gio.File.poll_mountable
().New in version 2.22.
- query_default_handler(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Raises:
- Returns:
a
Gio.AppInfo
if the handle was found,None
if there were errors. When you are done with it, release it withGObject.Object.unref
()- Return type:
Returns the
Gio.AppInfo
that is registered as the default application to handle the file specified by self.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- query_default_handler_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is done
Async version of
Gio.File.query_default_handler
().New in version 2.60.
- query_default_handler_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a
Gio.AppInfo
if the handle was found,None
if there were errors. When you are done with it, release it withGObject.Object.unref
()- Return type:
Finishes a
Gio.File.query_default_handler_async
() operation.New in version 2.60.
- query_exists(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Returns:
True
if the file exists (and can be detected without error),False
otherwise (or if cancelled).- Return type:
Utility function to check if a particular file exists. This is implemented using
Gio.File.query_info
() and as such does blocking I/O.Note that in many cases it is racy to first check for file existence and then execute something based on the outcome of that, because the file might have been created or removed in between the operations. The general approach to handling that is to not check, but just do the operation and handle the errors as they come.
As an example of race-free checking, take the case of reading a file, and if it doesn’t exist, creating it. There are two racy versions: read it, and on error create it; and: check if it exists, if not create it. These can both result in two processes creating the file (with perhaps a partially written file as the result). The correct approach is to always try to create the file with
Gio.File.create
() which will either atomically create the file or fail with aGio.IOErrorEnum.EXISTS
error.However, in many cases an existence check is useful in a user interface, for instance to make a menu item sensitive/insensitive, so that you don’t have to fool users that something is possible and then just show an error dialog. If you do this, you should make sure to also handle the errors that can happen due to races when you execute the operation.
- query_file_type(flags, cancellable)[source]¶
- Parameters:
flags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
passed toGio.File.query_info
()cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
The
Gio.FileType
of the file andGio.FileType.UNKNOWN
if the file does not exist- Return type:
Utility function to inspect the
Gio.FileType
of a file. This is implemented usingGio.File.query_info
() and as such does blocking I/O.The primary use case of this method is to check if a file is a regular file, directory, or symlink.
New in version 2.18.
- query_filesystem_info(attributes, cancellable)[source]¶
- Parameters:
attributes (
str
) – an attribute query stringcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.FileInfo
orNone
if there was an error. Free the returned object withGObject.Object.unref
().- Return type:
Similar to
Gio.File.query_info
(), but obtains information about the filesystem the self is on, rather than the file itself. For instance the amount of space available and the type of the filesystem.The attributes value is a string that specifies the attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “filesystem::*” means all attributes in the filesystem namespace. The standard namespace for filesystem attributes is “filesystem”. Common attributes of interest are
Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
(the total size of the filesystem in bytes),Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
(number of bytes available), andGio.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 errorGio.IOErrorEnum.CANCELLED
will be returned.If the file does not exist, the
Gio.IOErrorEnum.NOT_FOUND
error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- query_filesystem_info_async(attributes, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
attributes (
str
) – an attribute query stringio_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously gets the requested information about the filesystem that the specified self is on. The result is a
Gio.FileInfo
object that contains key-value attributes (such as type or size for the file).For more details, see
Gio.File.query_filesystem_info
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.query_info_finish
() to get the result of the operation.
- query_filesystem_info_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
Gio.FileInfo
for given self orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous filesystem info query. See
Gio.File.query_filesystem_info_async
().
- query_info(attributes, flags, cancellable)[source]¶
- Parameters:
attributes (
str
) – an attribute query stringflags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.FileInfo
for the given self, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Gets the requested information about specified self. The result is a
Gio.FileInfo
object that contains key-value attributes (such as the type or size of the file).The attributes value is a string that specifies the file attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “standard::*” means all attributes in the standard namespace. An example attribute query be “standard::*,owner::user”. The standard attributes are available as defines, like
Gio.FILE_ATTRIBUTE_STANDARD_NAME
.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.For symlinks, normally the information about the target of the symlink is returned, rather than information about the symlink itself. However if you pass
Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS
in flags the information about the symlink itself will be returned. Also, for symlinks that point to non-existing files the information about the symlink itself will be returned.If the file does not exist, the
Gio.IOErrorEnum.NOT_FOUND
error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- query_info_async(attributes, flags, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
attributes (
str
) – an attribute query stringflags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously gets the requested information about specified self. The result is a
Gio.FileInfo
object that contains key-value attributes (such as type or size for the file).For more details, see
Gio.File.query_info
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.query_info_finish
() to get the result of the operation.
- query_info_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
Gio.FileInfo
for given self orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file info query. See
Gio.File.query_info_async
().
- query_settable_attributes(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Raises:
- Returns:
a
Gio.FileAttributeInfoList
describing the settable attributes. When you are done with it, release it withGio.FileAttributeInfoList.unref
()- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.
- query_writable_namespaces(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Raises:
- Returns:
a
Gio.FileAttributeInfoList
describing the writable namespaces. When you are done with it, release it withGio.FileAttributeInfoList.unref
()- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.
- read(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
- Raises:
- Returns:
Gio.FileInputStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.If the file does not exist, the
Gio.IOErrorEnum.NOT_FOUND
error will be returned. If the file is a directory, theGio.IOErrorEnum.IS_DIRECTORY
error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- read_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously opens self for reading.
For more details, see
Gio.File.read
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.read_finish
() to get the result of the operation.
- read_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a
Gio.FileInputStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file read operation started with
Gio.File.read_async
().
- replace(etag, make_backup, flags, cancellable)[source]¶
- Parameters:
etag (
str
orNone
) – an optional entity tag for the currentGio.File
, orNone
to ignoreflags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.FileOutputStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Returns an output stream for overwriting the file, possibly creating a backup copy of the file first. If the file doesn’t exist, it will be created.
This will try to replace the file in the safest way possible so that any errors during the writing will not affect an already existing copy of the file. For instance, for local files it may write to a temporary file and then atomically rename over the destination when the stream is closed.
By default files created are generally readable by everyone, but if you pass
Gio.FileCreateFlags.PRIVATE
in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If you pass in a non-
None
etag value and self already exists, then this value is compared to the current entity tag of the file, and if they differ anGio.IOErrorEnum.WRONG_ETAG
error is returned. This generally means that the file has been changed since you last read it. You can get the new etag fromGio.FileOutputStream.get_etag
() after you’ve finished writing and closed theGio.FileOutputStream
. When you load a new file you can useGio.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 aGio.IOErrorEnum.CANT_CREATE_BACKUP
error will be returned. If you want to replace anyway, try again with make_backup set toFalse
.If the file is a directory the
Gio.IOErrorEnum.IS_DIRECTORY
error will be returned, and if the file is some other form of non-regular file then aGio.IOErrorEnum.NOT_REGULAR_FILE
error will be returned. Some file systems don’t allow all file names, and may return anGio.IOErrorEnum.INVALID_FILENAME
error, and if the name is to longGio.IOErrorEnum.FILENAME_TOO_LONG
will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- replace_async(etag, make_backup, flags, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
etag (
str
orNone
) – an entity tag for the currentGio.File
, orNone
to ignoreflags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first.
For more details, see
Gio.File.replace
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.replace_finish
() to get the result of the operation.
- replace_contents(contents, etag, make_backup, flags, cancellable)[source]¶
- Parameters:
contents (
bytes
) – a string containing the new contents for selfetag (
str
orNone
) – the old entity-tag for the document, orNone
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
True
if successful. If an error has occurred, this function will returnFalse
and set error appropriately if present.- new_etag:
a location to a new entity tag for the document. This should be freed with
GLib.free
() when no longer needed, orNone
- Return type:
Replaces the contents of self with contents of length bytes.
If etag is specified (not
None
), any existing file must have that etag, or the errorGio.IOErrorEnum.WRONG_ETAG
will be returned.If make_backup is
True
, this function will attempt to make a backup of self. Internally, it usesGio.File.replace
(), so will try to replace the file contents in the safest way possible. For example, atomic renames are used when replacing local files’ contents.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.The returned new_etag can be used to verify that the file hasn’t changed the next time it is saved over.
- replace_contents_async(contents, etag, make_backup, flags, cancellable, callback, *user_data)[source]¶
- Parameters:
contents (
bytes
) – string of contents to replace the file withetag (
str
orNone
) – a new entity tag for the self, orNone
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Starts an asynchronous replacement of self with the given contents of length bytes. etag will replace the document’s current entity tag.
When this operation has completed, callback will be called with user_user data, and the operation can be finalized with
Gio.File.replace_contents_finish
().If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If make_backup is
True
, this function will attempt to make a backup of self.Note that no copy of contents will be made, so it must stay valid until callback is called. See
Gio.File.replace_contents_bytes_async
() for aGLib.Bytes
version that will automatically hold a reference to the contents (without copying) for the duration of the call.
- replace_contents_bytes_async(contents, etag, make_backup, flags, cancellable, callback, *user_data)[source]¶
- Parameters:
contents (
GLib.Bytes
) – aGLib.Bytes
etag (
str
orNone
) – a new entity tag for the self, orNone
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Same as
Gio.File.replace_contents_async
() but takes aGLib.Bytes
input instead. This function will keep a ref on contents until the operation is done. UnlikeGio.File.replace_contents_async
() this allows forgetting about the content without waiting for the callback.When this operation has completed, callback will be called with user_user data, and the operation can be finalized with
Gio.File.replace_contents_finish
().New in version 2.40.
- replace_contents_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
True
on success,False
on failure.- new_etag:
a location of a new entity tag for the document. This should be freed with
GLib.free
() when it is no longer needed, orNone
- Return type:
Finishes an asynchronous replace of the given self. See
Gio.File.replace_contents_async
(). Sets new_etag to the new entity tag for the document, if present.
- replace_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a
Gio.FileOutputStream
, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file replace operation started with
Gio.File.replace_async
().
- replace_readwrite(etag, make_backup, flags, cancellable)[source]¶
- Parameters:
etag (
str
orNone
) – an optional entity tag for the currentGio.File
, orNone
to ignoreflags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.FileIOStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Returns an output stream for overwriting the file in readwrite mode, possibly creating a backup copy of the file first. If the file doesn’t exist, it will be created.
For details about the behaviour, see
Gio.File.replace
() which does the same thing but returns an output stream only.Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.
New in version 2.22.
- replace_readwrite_async(etag, make_backup, flags, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
etag (
str
orNone
) – an entity tag for the currentGio.File
, orNone
to ignoreflags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously overwrites the file in read-write mode, replacing the contents, possibly creating a backup copy of the file first.
For more details, see
Gio.File.replace_readwrite
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.replace_readwrite_finish
() to get the result of the operation.New in version 2.22.
- replace_readwrite_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a
Gio.FileIOStream
, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file replace operation started with
Gio.File.replace_readwrite_async
().New in version 2.22.
- resolve_relative_path(relative_path)[source]¶
- Parameters:
relative_path (
str
) – a given relative path string- Returns:
a
Gio.File
for the resolved path.- Return type:
Resolves a relative path for self to an absolute path.
This call does no blocking I/O.
If the relative_path is an absolute path name, the resolution is done absolutely (without taking self path as base).
- set_attribute(attribute, type, value_p, flags, cancellable)[source]¶
- Parameters:
attribute (
str
) – a string containing the attribute’s nametype (
Gio.FileAttributeType
) – The type of the attributevalue_p (
object
orNone
) – a pointer to the value (or the pointer itself if the type is a pointer type)flags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
- Return type:
Sets an attribute in the file with attribute name attribute to value_p.
Some attributes can be unset by setting type to
Gio.FileAttributeType.INVALID
and value_p toNone
.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 errorGio.IOErrorEnum.CANCELLED
will be returned.
- set_attribute_byte_string(attribute, value, flags, cancellable)[source]¶
- Parameters:
attribute (
str
) – a string containing the attribute’s namevalue (
str
) – a string containing the attribute’s new valueflags (
Gio.FileQueryInfoFlags
) – aGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
True
if the attribute was successfully set to value in the self,False
otherwise.- Return type:
Sets attribute of type
Gio.FileAttributeType.BYTE_STRING
to value. If attribute is of a different type, this operation will fail, returningFalse
.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 errorGio.IOErrorEnum.CANCELLED
will be returned.
- set_attribute_int32(attribute, value, flags, cancellable)[source]¶
- Parameters:
attribute (
str
) – a string containing the attribute’s namevalue (
int
) – a #gint32 containing the attribute’s new valueflags (
Gio.FileQueryInfoFlags
) – aGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
True
if the attribute was successfully set to value in the self,False
otherwise.- Return type:
Sets attribute of type
Gio.FileAttributeType.INT32
to value. If attribute is of a different type, this operation will fail.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- set_attribute_int64(attribute, value, flags, cancellable)[source]¶
- Parameters:
attribute (
str
) – a string containing the attribute’s namevalue (
int
) – a #guint64 containing the attribute’s new valueflags (
Gio.FileQueryInfoFlags
) – aGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
True
if the attribute was successfully set,False
otherwise.- Return type:
Sets attribute of type
Gio.FileAttributeType.INT64
to value. If attribute is of a different type, this operation will fail.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- set_attribute_string(attribute, value, flags, cancellable)[source]¶
- Parameters:
attribute (
str
) – a string containing the attribute’s namevalue (
str
) – a string containing the attribute’s valueflags (
Gio.FileQueryInfoFlags
) –Gio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
True
if the attribute was successfully set,False
otherwise.- Return type:
Sets attribute of type
Gio.FileAttributeType.STRING
to value. If attribute is of a different type, this operation will fail.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- set_attribute_uint32(attribute, value, flags, cancellable)[source]¶
- Parameters:
attribute (
str
) – a string containing the attribute’s namevalue (
int
) – a #guint32 containing the attribute’s new valueflags (
Gio.FileQueryInfoFlags
) – aGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
True
if the attribute was successfully set to value in the self,False
otherwise.- Return type:
Sets attribute of type
Gio.FileAttributeType.UINT32
to value. If attribute is of a different type, this operation will fail.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- set_attribute_uint64(attribute, value, flags, cancellable)[source]¶
- Parameters:
attribute (
str
) – a string containing the attribute’s namevalue (
int
) – a #guint64 containing the attribute’s new valueflags (
Gio.FileQueryInfoFlags
) – aGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
True
if the attribute was successfully set to value in the self,False
otherwise.- Return type:
Sets attribute of type
Gio.FileAttributeType.UINT64
to value. If attribute is of a different type, this operation will fail.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- set_attributes_async(info, flags, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
info (
Gio.FileInfo
) – aGio.FileInfo
flags (
Gio.FileQueryInfoFlags
) – aGio.FileQueryInfoFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously sets the attributes of self with info.
For more details, see
Gio.File.set_attributes_from_info
(), which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.set_attributes_finish
() to get the result of the operation.
- set_attributes_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
True
if the attributes were set correctly,False
otherwise.- info:
- Return type:
(
bool
, info:Gio.FileInfo
)
Finishes setting an attribute started in
Gio.File.set_attributes_async
().
- set_attributes_from_info(info, flags, cancellable)[source]¶
- Parameters:
info (
Gio.FileInfo
) – aGio.FileInfo
flags (
Gio.FileQueryInfoFlags
) –Gio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
- Return type:
Tries to set all attributes in the
Gio.FileInfo
on the target values, not stopping on the first error.If there is any error during this operation then error will be set to the first error. Error on particular fields are flagged by setting the “status” field in the attribute value to
Gio.FileAttributeStatus.ERROR_SETTING
, which means you can also detect further errors.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- set_display_name(display_name, cancellable)[source]¶
- Parameters:
display_name (
str
) – a stringcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Raises:
- Returns:
a
Gio.File
specifying what self was renamed to, orNone
if there was an error. Free the returned object withGObject.Object.unref
().- Return type:
Renames self to the specified display name.
The display name is converted from UTF-8 to the correct encoding for the target filesystem if possible and the self is renamed to this.
If you want to implement a rename operation in the user interface the edit name (
Gio.FILE_ATTRIBUTE_STANDARD_EDIT_NAME
) should be used as the initial value in the rename widget, and then the result after editing should be passed toGio.File.set_display_name
().On success the resulting converted filename is returned.
If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- set_display_name_async(display_name, io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
display_name (
str
) – a stringio_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously sets the display name for a given
Gio.File
.For more details, see
Gio.File.set_display_name
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.set_display_name_finish
() to get the result of the operation.
- set_display_name_finish(res)[source]¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
a
Gio.File
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes setting a display name started with
Gio.File.set_display_name_async
().
- start_mountable(flags, start_operation, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.DriveStartFlags
) – flags affecting the operationstart_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
, orNone
to avoid user interactioncancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied, orNone
user_data (
object
orNone
) – the data to pass to callback function
Starts a file of type
Gio.FileType.MOUNTABLE
. Using start_operation, you can request callbacks when, for instance, passwords are needed during authentication.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.mount_mountable_finish
() to get the result of the operation.New in version 2.22.
- start_mountable_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
True
if the operation finished successfully.False
otherwise.- Return type:
Finishes a start operation. See
Gio.File.start_mountable
() for details.Finish an asynchronous start operation that was started with
Gio.File.start_mountable
().New in version 2.22.
- stop_mountable(flags, mount_operation, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.MountUnmountFlags
) – flags affecting the operationmount_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
, orNone
to avoid user interaction.cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied, orNone
user_data (
object
orNone
) – the data to pass to callback function
Stops a file of type
Gio.FileType.MOUNTABLE
.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.stop_mountable_finish
() to get the result of the operation.New in version 2.22.
- stop_mountable_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
True
if the operation finished successfully.False
otherwise.- Return type:
Finishes a stop operation, see
Gio.File.stop_mountable
() for details.Finish an asynchronous stop operation that was started with
Gio.File.stop_mountable
().New in version 2.22.
- supports_thread_contexts()[source]¶
- Returns:
Whether or not self supports thread-default contexts.
- Return type:
Checks if self supports ‘thread-default contexts [g-main-context-push-thread-default-context]’. If this returns
False
, you cannot perform asynchronous operations on self in a thread that has a thread-default context.New in version 2.22.
- trash(cancellable)[source]¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Raises:
- Returns:
- Return type:
Sends self to the “Trashcan”, if possible. This is similar to deleting it, but the user can recover it before emptying the trashcan. Not all file systems support trashing, so this call can return the
Gio.IOErrorEnum.NOT_SUPPORTED
error. Since GLib 2.66, thex-gvfs-notrash
unix mount option can be used to disableGio.File.trash
() support for certain mounts, theGio.IOErrorEnum.NOT_SUPPORTED
error will be returned in that case.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- trash_async(io_priority, cancellable, callback, *user_data)[source]¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously sends self to the Trash location, if possible.
New in version 2.38.
- trash_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
- Return type:
Finishes an asynchronous file trashing operation, started with
Gio.File.trash_async
().New in version 2.38.
- unmount_mountable(flags, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.MountUnmountFlags
) – flags affecting the operationcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Unmounts a file of type
Gio.FileType.MOUNTABLE
.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.unmount_mountable_finish
() to get the result of the operation.Deprecated since version 2.22: Use
Gio.File.unmount_mountable_with_operation
() instead.
- unmount_mountable_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
True
if the operation finished successfully.False
otherwise.- Return type:
Finishes an unmount operation, see
Gio.File.unmount_mountable
() for details.Finish an asynchronous unmount operation that was started with
Gio.File.unmount_mountable
().Deprecated since version 2.22: Use
Gio.File.unmount_mountable_with_operation_finish
() instead.
- unmount_mountable_with_operation(flags, mount_operation, cancellable, callback, *user_data)[source]¶
- Parameters:
flags (
Gio.MountUnmountFlags
) – flags affecting the operationmount_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
, orNone
to avoid user interactioncancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Unmounts a file of type
Gio.FileType.MOUNTABLE
.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.unmount_mountable_finish
() to get the result of the operation.New in version 2.22.
- unmount_mountable_with_operation_finish(result)[source]¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Raises:
- Returns:
True
if the operation finished successfully.False
otherwise.- Return type:
Finishes an unmount operation, see
Gio.File.unmount_mountable_with_operation
() for details.Finish an asynchronous unmount operation that was started with
Gio.File.unmount_mountable_with_operation
().New in version 2.22.
- do_append_to(flags, cancellable) virtual¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
a
Gio.FileOutputStream
, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Gets an output stream for appending data to the file. If the file doesn’t already exist it is created.
By default files created are generally readable by everyone, but if you pass
Gio.FileCreateFlags.PRIVATE
in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.Some file systems don’t allow all file names, and may return an
Gio.IOErrorEnum.INVALID_FILENAME
error. If the file is a directory theGio.IOErrorEnum.IS_DIRECTORY
error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- do_append_to_async(flags, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously opens file for appending.
For more details, see
Gio.File.append_to
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.append_to_finish
() to get the result of the operation.
- do_append_to_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) –Gio.AsyncResult
- Returns:
a valid
Gio.FileOutputStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file append operation started with
Gio.File.append_to_async
().
- do_copy(destination, flags, cancellable, progress_callback, progress_callback_data) virtual¶
- Parameters:
flags (
Gio.FileCopyFlags
) – set ofGio.FileCopyFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignoreprogress_callback (
Gio.FileProgressCallback
orNone
) – function to callback with progress information, orNone
if progress information is not neededprogress_callback_data (
object
orNone
) – user data to pass to progress_callback
- Returns:
- Return type:
Copies the file source to the location specified by destination. Can not handle recursive copies of directories.
If the flag
Gio.FileCopyFlags.OVERWRITE
is specified an already existing destination file is overwritten.If the flag
Gio.FileCopyFlags.NOFOLLOW_SYMLINKS
is specified then symlinks will be copied as symlinks, otherwise the target of the source symlink will be copied.If the flag
Gio.FileCopyFlags.ALL_METADATA
is specified then all the metadata that is possible to copy is copied, not just the default subset (which, for instance, does not include the owner, seeGio.FileInfo
).If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If progress_callback is not
None
, then the operation can be monitored by setting this to aGio.FileProgressCallback
function. progress_callback_data will be passed to this function. It is guaranteed that this callback will be called after all data has been transferred with the total number of bytes copied during the operation.If the source file does not exist, then the
Gio.IOErrorEnum.NOT_FOUND
error is returned, independent on the status of the destination.If
Gio.FileCopyFlags.OVERWRITE
is not specified and the target exists, then the errorGio.IOErrorEnum.EXISTS
is returned.If trying to overwrite a file over a directory, the
Gio.IOErrorEnum.IS_DIRECTORY
error is returned. If trying to overwrite a directory with a directory theGio.IOErrorEnum.WOULD_MERGE
error is returned.If the source is a directory and the target does not exist, or
Gio.FileCopyFlags.OVERWRITE
is specified and the target is a file, then theGio.IOErrorEnum.WOULD_RECURSE
error is returned.If you are interested in copying the
Gio.File
object itself (not the on-disk file), seeGio.File.dup
().
- do_copy_async(destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.FileCopyFlags
) – set ofGio.FileCopyFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignoreprogress_callback (
Gio.FileProgressCallback
orNone
) – function to callback with progress information, orNone
if progress information is not neededprogress_callback_data (
object
orNone
) – user data to pass to progress_callbackcallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied
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 inGio.File.copy
(). The callback will run in the default main context of the thread callingGio.File.copy_async
() — the same context as callback is run in.When the operation is finished, callback will be called. You can then call
Gio.File.copy_finish
() to get the result of the operation.
- do_copy_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
- Return type:
Finishes copying the file started with
Gio.File.copy_async
().
- do_create(flags, cancellable) virtual¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
a
Gio.FileOutputStream
for the newly created file, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Creates a new file and returns an output stream for writing to it. The file must not already exist.
By default files created are generally readable by everyone, but if you pass
Gio.FileCreateFlags.PRIVATE
in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If a file or directory with this name already exists the
Gio.IOErrorEnum.EXISTS
error will be returned. Some file systems don’t allow all file names, and may return anGio.IOErrorEnum.INVALID_FILENAME
error, and if the name is to longGio.IOErrorEnum.FILENAME_TOO_LONG
will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- do_create_async(flags, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously creates a new file and returns an output stream for writing to it. The file must not already exist.
For more details, see
Gio.File.create
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.create_finish
() to get the result of the operation.
- do_create_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
a
Gio.FileOutputStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file create operation started with
Gio.File.create_async
().
- do_create_readwrite(flags, cancellable) virtual¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
a
Gio.FileIOStream
for the newly created file, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Creates a new file and returns a stream for reading and writing to it. The file must not already exist.
By default files created are generally readable by everyone, but if you pass
Gio.FileCreateFlags.PRIVATE
in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If a file or directory with this name already exists, the
Gio.IOErrorEnum.EXISTS
error will be returned. Some file systems don’t allow all file names, and may return anGio.IOErrorEnum.INVALID_FILENAME
error, and if the name is too long,Gio.IOErrorEnum.FILENAME_TOO_LONG
will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.
New in version 2.22.
- do_create_readwrite_async(flags, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously creates a new file and returns a stream for reading and writing to it. The file must not already exist.
For more details, see
Gio.File.create_readwrite
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.create_readwrite_finish
() to get the result of the operation.New in version 2.22.
- do_create_readwrite_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
a
Gio.FileIOStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file create operation started with
Gio.File.create_readwrite_async
().New in version 2.22.
- do_delete_file(cancellable) virtual¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Returns:
- Return type:
Deletes a file. If the file is a directory, it will only be deleted if it is empty. This has the same semantics as
GLib.unlink
().If file doesn’t exist,
Gio.IOErrorEnum.NOT_FOUND
will be returned. This allows for deletion to be implemented avoiding time-of-check to time-of-use races :g_autoptr(GError) local_error = NULL; if (!g_file_delete (my_file, my_cancellable, &local_error) && !g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { // deletion failed for some reason other than the file not existing: // so report the error g_warning ("Failed to delete %s: %s", g_file_peek_path (my_file), local_error->message); }
If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_delete_file_async(io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously delete a file. If the file is a directory, it will only be deleted if it is empty. This has the same semantics as
GLib.unlink
().New in version 2.34.
- do_delete_file_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
- Return type:
Finishes deleting a file started with
Gio.File.delete_async
().New in version 2.34.
- do_dup() virtual¶
-
Duplicates a
Gio.File
handle. This operation does not duplicate the actual file or directory represented by theGio.File
; seeGio.File.copy
() if attempting to copy a file.Gio.File.dup
() is useful when a second handle is needed to the same underlying file, for use in a separate thread (Gio.File
is not thread-safe). For use within the same thread, useGObject.Object.ref
() to increment the existing object’s reference count.This call does no blocking I/O.
- do_eject_mountable(flags, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.MountUnmountFlags
) – flags affecting the operationcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
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 errorGio.IOErrorEnum.CANCELLED
will be returned.Deprecated since version 2.22: Use
Gio.File.eject_mountable_with_operation
() instead.
- do_eject_mountable_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
- Return type:
Finishes an asynchronous eject operation started by
Gio.File.eject_mountable
().Deprecated since version 2.22: Use
Gio.File.eject_mountable_with_operation_finish
() instead.
- do_eject_mountable_with_operation(flags, mount_operation, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.MountUnmountFlags
) – flags affecting the operationmount_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
, orNone
to avoid user interactioncancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Starts an asynchronous eject on a mountable. When this operation has completed, callback will be called with user_user data, and the operation can be finalized with
Gio.File.eject_mountable_with_operation_finish
().If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.New in version 2.22.
- do_eject_mountable_with_operation_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
- Return type:
Finishes an asynchronous eject operation started by
Gio.File.eject_mountable_with_operation
().New in version 2.22.
- do_enumerate_children(attributes, flags, cancellable) virtual¶
- Parameters:
attributes (
str
) – an attribute query stringflags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
A
Gio.FileEnumerator
if successful,None
on error. Free the returned object withGObject.Object.unref
().- Return type:
Gets the requested information about the files in a directory. The result is a
Gio.FileEnumerator
object that will give outGio.FileInfo
objects for all the files in the directory.The attributes value is a string that specifies the file attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “standard::*” means all attributes in the standard namespace. An example attribute query be “standard::*,owner::user”. The standard attributes are available as defines, like
Gio.FILE_ATTRIBUTE_STANDARD_NAME
.Gio.FILE_ATTRIBUTE_STANDARD_NAME
should always be specified if you plan to callGio.FileEnumerator.get_child
() orGio.FileEnumerator.iterate
() on the returned enumerator.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If the file does not exist, the
Gio.IOErrorEnum.NOT_FOUND
error will be returned. If the file is not a directory, theGio.IOErrorEnum.NOT_DIRECTORY
error will be returned. Other errors are possible too.
- do_enumerate_children_async(attributes, flags, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
attributes (
str
) – an attribute query stringflags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously gets the requested information about the files in a directory. The result is a
Gio.FileEnumerator
object that will give outGio.FileInfo
objects for all the files in the directory.For more details, see
Gio.File.enumerate_children
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.enumerate_children_finish
() to get the result of the operation.
- do_enumerate_children_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
a
Gio.FileEnumerator
orNone
if an error occurred. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an async enumerate children operation. See
Gio.File.enumerate_children_async
().
- do_equal(file2) virtual¶
- Parameters:
- Returns:
True
if file1 and file2 are equal.- Return type:
Checks if the two given
Gio.Files
refer to the same file.Note that two
Gio.Files
that differ can still refer to the same file on the filesystem due to various forms of filename aliasing.This call does no blocking I/O.
- do_find_enclosing_mount(cancellable) virtual¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Returns:
a
Gio.Mount
where the file is located orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Gets a
Gio.Mount
for theGio.File
.Gio.Mount
is returned only for user interesting locations, seeGio.VolumeMonitor
. If theGio.FileIface
for file does not have a #mount, error will be set toGio.IOErrorEnum.NOT_FOUND
andNone
#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 errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_find_enclosing_mount_async(io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously gets the mount for the file.
For more details, see
Gio.File.find_enclosing_mount
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.find_enclosing_mount_finish
() to get the result of the operation.
- do_find_enclosing_mount_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
Gio.Mount
for given file orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous find mount request. See
Gio.File.find_enclosing_mount_async
().
- do_get_basename() virtual¶
- Returns:
string containing the
Gio.File
's base name, orNone
if givenGio.File
is invalid. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
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 withGio.File.query_info
().This call does no blocking I/O.
- do_get_child_for_display_name(display_name) virtual¶
- Parameters:
display_name (
str
) – string to a possible child- Returns:
a
Gio.File
to the specified child, orNone
if the display name couldn’t be converted. Free the returned object withGObject.Object.unref
().- Return type:
Gets the child of file for a given display_name (i.e. a UTF-8 version of the name). If this function fails, it returns
None
and error will be set. This is very useful when constructing aGio.File
for a new file and the user entered the filename in the user interface, for instance when you select a directory and type a filename in the file selector.This call does no blocking I/O.
- do_get_parent() virtual¶
- Returns:
a
Gio.File
structure to the parent of the givenGio.File
orNone
if there is no parent. Free the returned object withGObject.Object.unref
().- Return type:
Gets the parent directory for the file. If the file represents the root directory of the file system, then
None
will be returned.This call does no blocking I/O.
- do_get_parse_name() virtual¶
- Returns:
a string containing the
Gio.File
's parse name. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
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 usingGio.File.parse_name
().This is generally used to show the
Gio.File
as a nice full-pathname kind of string in a user interface, like in a location entry.For local files with names that can safely be converted to UTF-8 the pathname is used, otherwise the IRI is used (a form of URI that allows UTF-8 characters unescaped).
This call does no blocking I/O.
- do_get_path() virtual¶
- Returns:
string containing the
Gio.File
's path, orNone
if no such path exists. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
Gets the local pathname for
Gio.File
, if one exists. If non-None
, this is guaranteed to be an absolute, canonical path. It might contain symlinks.This call does no blocking I/O.
- do_get_relative_path(descendant) virtual¶
- Parameters:
- Returns:
string with the relative path from descendant to parent, or
None
if descendant doesn’t have parent as prefix. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
Gets the path for descendant relative to parent.
This call does no blocking I/O.
- do_get_uri() virtual¶
- Returns:
a string containing the
Gio.File
's URI. If theGio.File
was constructed with an invalid URI, an invalid URI is returned. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
Gets the URI for the file.
This call does no blocking I/O.
- do_get_uri_scheme() virtual¶
- Returns:
a string containing the URI scheme for the given
Gio.File
orNone
if theGio.File
was constructed with an invalid URI. The returned string should be freed withGLib.free
() when no longer needed.- Return type:
Gets the URI scheme for a
Gio.File
. RFC 3986 decodes the scheme as:URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
Common schemes include “file”, “http”, “ftp”, etc.
The scheme can be different from the one used to construct the
Gio.File
, in that it might be replaced with one that is logically equivalent to theGio.File
.This call does no blocking I/O.
- do_has_uri_scheme(uri_scheme) virtual¶
- Parameters:
uri_scheme (
str
) – a string containing a URI scheme- Returns:
True
ifGio.File
's backend supports the given URI scheme,False
if URI scheme isNone
, not supported, orGio.File
is invalid.- Return type:
Checks to see if a
Gio.File
has a given URI scheme.This call does no blocking I/O.
- do_hash() virtual¶
- Returns:
0 if file is not a valid
Gio.File
, otherwise an integer that can be used as hash value for theGio.File
. This function is intended for easily hashing aGio.File
to add to aGLib.HashTable
or similar data structure.- Return type:
Creates a hash value for a
Gio.File
.This call does no blocking I/O.
- do_is_native() virtual¶
-
Checks to see if a file is native to the platform.
A native file is one expressed in the platform-native filename format, e.g. “C:\Windows” or “/usr/bin/”. This does not mean the file is local, as it might be on a locally mounted remote filesystem.
On some systems non-native files may be available using the native filesystem via a userspace filesystem (FUSE), in these cases this call will return
False
, butGio.File.get_path
() will still return a native path.This call does no blocking I/O.
- do_make_directory(cancellable) virtual¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Returns:
- Return type:
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, seeGio.File.make_directory_with_parents
(). This function will fail if the parent directory does not exist, setting error toGio.IOErrorEnum.NOT_FOUND
. If the file system doesn’t support creating directories, this function will fail, setting error toGio.IOErrorEnum.NOT_SUPPORTED
.For a local
Gio.File
the newly created directory will have the default (current) ownership and permissions of the current process.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_make_directory_async(io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously creates a directory.
New in version 2.38.
- do_make_directory_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
- Return type:
Finishes an asynchronous directory creation, started with
Gio.File.make_directory_async
().New in version 2.38.
- do_make_symbolic_link(symlink_value, cancellable) virtual¶
- Parameters:
symlink_value (
str
) – a string with the path for the target of the new symlinkcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
- Return type:
Creates a symbolic link named file which contains the string symlink_value.
If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_make_symbolic_link_async(symlink_value, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
symlink_value (
str
) – a string with the path for the target of the new symlinkio_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously creates a symbolic link named file which contains the string symlink_value.
New in version 2.74.
- do_make_symbolic_link_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
- Return type:
Finishes an asynchronous symbolic link creation, started with
Gio.File.make_symbolic_link_async
().New in version 2.74.
- do_measure_disk_usage(flags, cancellable, progress_callback, progress_data) virtual¶
- Parameters:
flags (
Gio.FileMeasureFlags
) –Gio.FileMeasureFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
progress_callback (
Gio.FileMeasureProgressCallback
orNone
) – aGio.FileMeasureProgressCallback
progress_data (
object
orNone
) – user_data for progress_callback
- Returns:
True
if successful, with the out parameters set.False
otherwise, with error set.- disk_usage:
the number of bytes of disk space used
- num_dirs:
the number of directories encountered
- num_files:
the number of non-directories encountered
- Return type:
Recursively measures the disk usage of file.
This is essentially an analog of the ‘du’ command, but it also reports the number of directories and non-directory files encountered (including things like symbolic links).
By default, errors are only reported against the toplevel file itself. Errors found while recursing are silently ignored, unless
Gio.FileMeasureFlags.REPORT_ANY_ERROR
is given in flags.The returned size, disk_usage, is in bytes and should be formatted with
GLib.format_size
() in order to get something reasonable for showing in a user interface.progress_callback and progress_data can be given to request periodic progress updates while scanning. See the documentation for
Gio.FileMeasureProgressCallback
for information about when and how the callback will be invoked.New in version 2.38.
- do_measure_disk_usage_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – theGio.AsyncResult
passed to yourGio.AsyncReadyCallback
- Returns:
True
if successful, with the out parameters set.False
otherwise, with error set.- disk_usage:
the number of bytes of disk space used
- num_dirs:
the number of directories encountered
- num_files:
the number of non-directories encountered
- Return type:
Collects the results from an earlier call to g_file_measure_disk_usage_async(). See
Gio.File.measure_disk_usage
() for more information.New in version 2.38.
- do_monitor_dir(flags, cancellable) virtual¶
- Parameters:
flags (
Gio.FileMonitorFlags
) – a set ofGio.FileMonitorFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
a
Gio.FileMonitor
for the given file, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.It does not make sense for flags to contain
Gio.FileMonitorFlags.WATCH_HARD_LINKS
, since hard links can not be made to directories. It is not possible to monitor all the files in a directory for changes made via hard links; if you want to do this then you must register individual watches withGio.File.monitor
().
- do_monitor_file(flags, cancellable) virtual¶
- Parameters:
flags (
Gio.FileMonitorFlags
) – a set ofGio.FileMonitorFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
a
Gio.FileMonitor
for the given file, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.If flags contains
Gio.FileMonitorFlags.WATCH_HARD_LINKS
then the monitor will also attempt to report changes made to the file via another filename (ie, a hard link). Without this flag, you can only rely on changes made through the filename contained in file to be reported. Using this flag may result in an increase in resource usage, and may not have any effect depending on theGio.FileMonitor
backend and/or filesystem type.
- do_mount_enclosing_volume(flags, mount_operation, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.MountMountFlags
) – flags affecting the operationmount_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
orNone
to avoid user interactioncancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied, orNone
user_data (
object
orNone
) – the data to pass to callback function
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 errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_mount_enclosing_volume_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
True
if successful. If an error has occurred, this function will returnFalse
and set error appropriately if present.- Return type:
Finishes a mount operation started by
Gio.File.mount_enclosing_volume
().
- do_mount_mountable(flags, mount_operation, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.MountMountFlags
) – flags affecting the operationmount_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
, orNone
to avoid user interactioncancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Mounts a file of type
Gio.FileType.MOUNTABLE
. Using mount_operation, you can request callbacks when, for instance, passwords are needed during authentication.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.mount_mountable_finish
() to get the result of the operation.
- do_mount_mountable_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
a
Gio.File
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes a mount operation. See
Gio.File.mount_mountable
() for details.Finish an asynchronous mount operation that was started with
Gio.File.mount_mountable
().
- do_move(destination, flags, cancellable, progress_callback, progress_callback_data) virtual¶
- Parameters:
destination (
Gio.File
) –Gio.File
pointing to the destination locationflags (
Gio.FileCopyFlags
) – set ofGio.FileCopyFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignoreprogress_callback (
Gio.FileProgressCallback
orNone
) –Gio.FileProgressCallback
function for updatesprogress_callback_data (
object
orNone
) –object
to user data for the callback function
- Returns:
- Return type:
Tries to move the file or directory source to the location specified by destination. If native move operations are supported then this is used, otherwise a copy + delete fallback is used. The native implementation may support moving directories (for instance on moves inside the same filesystem), but the fallback code does not.
If the flag
Gio.FileCopyFlags.OVERWRITE
is specified an already existing destination file is overwritten.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If progress_callback is not
None
, then the operation can be monitored by setting this to aGio.FileProgressCallback
function. progress_callback_data will be passed to this function. It is guaranteed that this callback will be called after all data has been transferred with the total number of bytes copied during the operation.If the source file does not exist, then the
Gio.IOErrorEnum.NOT_FOUND
error is returned, independent on the status of the destination.If
Gio.FileCopyFlags.OVERWRITE
is not specified and the target exists, then the errorGio.IOErrorEnum.EXISTS
is returned.If trying to overwrite a file over a directory, the
Gio.IOErrorEnum.IS_DIRECTORY
error is returned. If trying to overwrite a directory with a directory theGio.IOErrorEnum.WOULD_MERGE
error is returned.If the source is a directory and the target does not exist, or
Gio.FileCopyFlags.OVERWRITE
is specified and the target is a file, then theGio.IOErrorEnum.WOULD_RECURSE
error may be returned (if the native move operation isn’t available).
- do_move_async(destination, flags, io_priority, cancellable, progress_callback, progress_callback_data, callback, *user_data) virtual¶
- Parameters:
destination (
Gio.File
) –Gio.File
pointing to the destination locationflags (
Gio.FileCopyFlags
) – set ofGio.FileCopyFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignoreprogress_callback (
Gio.FileProgressCallback
orNone
) –Gio.FileProgressCallback
function for updatesprogress_callback_data (
object
orNone
) –object
to user data for the callback functioncallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously moves a file source to the location of destination. For details of the behaviour, see
Gio.File.move
().If progress_callback is not
None
, then that function that will be called just like inGio.File.move
(). The callback will run in the default main context of the thread callingGio.File.move_async
() — the same context as callback is run in.When the operation is finished, callback will be called. You can then call
Gio.File.move_finish
() to get the result of the operation.New in version 2.72.
- do_move_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
- Return type:
Finishes an asynchronous file movement, started with
Gio.File.move_async
().New in version 2.72.
- do_open_readwrite(cancellable) virtual¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
- Returns:
Gio.FileIOStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Opens an existing file for reading and writing. The result is a
Gio.FileIOStream
that can be used to read and write the contents of the file.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If the file does not exist, the
Gio.IOErrorEnum.NOT_FOUND
error will be returned. If the file is a directory, theGio.IOErrorEnum.IS_DIRECTORY
error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on. Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.New in version 2.22.
- do_open_readwrite_async(io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously opens file for reading and writing.
For more details, see
Gio.File.open_readwrite
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.open_readwrite_finish
() to get the result of the operation.New in version 2.22.
- do_open_readwrite_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
a
Gio.FileIOStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file read operation started with
Gio.File.open_readwrite_async
().New in version 2.22.
- do_poll_mountable(cancellable, callback, *user_data) virtual¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied, orNone
user_data (
object
orNone
) – the data to pass to callback function
Polls a file of type
Gio.FileType.MOUNTABLE
.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.mount_mountable_finish
() to get the result of the operation.New in version 2.22.
- do_poll_mountable_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
True
if the operation finished successfully.False
otherwise.- Return type:
Finishes a poll operation. See
Gio.File.poll_mountable
() for details.Finish an asynchronous poll operation that was polled with
Gio.File.poll_mountable
().New in version 2.22.
- do_prefix_matches(file) virtual¶
- Parameters:
- Returns:
True
if the file's parent, grandparent, etc is prefix,False
otherwise.- Return type:
Checks whether file has the prefix specified by prefix.
In other words, if the names of initial elements of file's pathname match prefix. Only full pathname elements are matched, so a path like /foo is not considered a prefix of /foobar, only of /foo/bar.
A
Gio.File
is not a prefix of itself. If you want to check for equality, useGio.File.equal
().This call does no I/O, as it works purely on names. As such it can sometimes return
False
even if file is inside a prefix (from a filesystem point of view), because the prefix of file is an alias of prefix.
- do_query_filesystem_info(attributes, cancellable) virtual¶
- Parameters:
attributes (
str
) – an attribute query stringcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
a
Gio.FileInfo
orNone
if there was an error. Free the returned object withGObject.Object.unref
().- Return type:
Similar to
Gio.File.query_info
(), but obtains information about the filesystem the file is on, rather than the file itself. For instance the amount of space available and the type of the filesystem.The attributes value is a string that specifies the attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “filesystem::*” means all attributes in the filesystem namespace. The standard namespace for filesystem attributes is “filesystem”. Common attributes of interest are
Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
(the total size of the filesystem in bytes),Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
(number of bytes available), andGio.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 errorGio.IOErrorEnum.CANCELLED
will be returned.If the file does not exist, the
Gio.IOErrorEnum.NOT_FOUND
error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- do_query_filesystem_info_async(attributes, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
attributes (
str
) – an attribute query stringio_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously gets the requested information about the filesystem that the specified file is on. The result is a
Gio.FileInfo
object that contains key-value attributes (such as type or size for the file).For more details, see
Gio.File.query_filesystem_info
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.query_info_finish
() to get the result of the operation.
- do_query_filesystem_info_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
Gio.FileInfo
for given file orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous filesystem info query. See
Gio.File.query_filesystem_info_async
().
- do_query_info(attributes, flags, cancellable) virtual¶
- Parameters:
attributes (
str
) – an attribute query stringflags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
a
Gio.FileInfo
for the given file, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Gets the requested information about specified file. The result is a
Gio.FileInfo
object that contains key-value attributes (such as the type or size of the file).The attributes value is a string that specifies the file attributes that should be gathered. It is not an error if it’s not possible to read a particular requested attribute from a file - it just won’t be set. attributes should be a comma-separated list of attributes or attribute wildcards. The wildcard “*” means all attributes, and a wildcard like “standard::*” means all attributes in the standard namespace. An example attribute query be “standard::*,owner::user”. The standard attributes are available as defines, like
Gio.FILE_ATTRIBUTE_STANDARD_NAME
.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.For symlinks, normally the information about the target of the symlink is returned, rather than information about the symlink itself. However if you pass
Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS
in flags the information about the symlink itself will be returned. Also, for symlinks that point to non-existing files the information about the symlink itself will be returned.If the file does not exist, the
Gio.IOErrorEnum.NOT_FOUND
error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- do_query_info_async(attributes, flags, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
attributes (
str
) – an attribute query stringflags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously gets the requested information about specified file. The result is a
Gio.FileInfo
object that contains key-value attributes (such as type or size for the file).For more details, see
Gio.File.query_info
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.query_info_finish
() to get the result of the operation.
- do_query_info_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
Gio.FileInfo
for given file orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file info query. See
Gio.File.query_info_async
().
- do_query_settable_attributes(cancellable) virtual¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Returns:
a
Gio.FileAttributeInfoList
describing the settable attributes. When you are done with it, release it withGio.FileAttributeInfoList.unref
()- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_query_writable_namespaces(cancellable) virtual¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Returns:
a
Gio.FileAttributeInfoList
describing the writable namespaces. When you are done with it, release it withGio.FileAttributeInfoList.unref
()- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_read_async(io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously opens file for reading.
For more details, see
Gio.File.read
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.read_finish
() to get the result of the operation.
- do_read_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
a
Gio.FileInputStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file read operation started with
Gio.File.read_async
().
- do_read_fn(cancellable) virtual¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGio.Cancellable
- Returns:
Gio.FileInputStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
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 errorGio.IOErrorEnum.CANCELLED
will be returned.If the file does not exist, the
Gio.IOErrorEnum.NOT_FOUND
error will be returned. If the file is a directory, theGio.IOErrorEnum.IS_DIRECTORY
error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- do_replace(etag, make_backup, flags, cancellable) virtual¶
- Parameters:
etag (
str
orNone
) – an optional entity tag for the currentGio.File
, orNone
to ignoreflags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
a
Gio.FileOutputStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Returns an output stream for overwriting the file, possibly creating a backup copy of the file first. If the file doesn’t exist, it will be created.
This will try to replace the file in the safest way possible so that any errors during the writing will not affect an already existing copy of the file. For instance, for local files it may write to a temporary file and then atomically rename over the destination when the stream is closed.
By default files created are generally readable by everyone, but if you pass
Gio.FileCreateFlags.PRIVATE
in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.If you pass in a non-
None
etag value and file already exists, then this value is compared to the current entity tag of the file, and if they differ anGio.IOErrorEnum.WRONG_ETAG
error is returned. This generally means that the file has been changed since you last read it. You can get the new etag fromGio.FileOutputStream.get_etag
() after you’ve finished writing and closed theGio.FileOutputStream
. When you load a new file you can useGio.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 aGio.IOErrorEnum.CANT_CREATE_BACKUP
error will be returned. If you want to replace anyway, try again with make_backup set toFalse
.If the file is a directory the
Gio.IOErrorEnum.IS_DIRECTORY
error will be returned, and if the file is some other form of non-regular file then aGio.IOErrorEnum.NOT_REGULAR_FILE
error will be returned. Some file systems don’t allow all file names, and may return anGio.IOErrorEnum.INVALID_FILENAME
error, and if the name is to longGio.IOErrorEnum.FILENAME_TOO_LONG
will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on.
- do_replace_async(etag, make_backup, flags, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
etag (
str
orNone
) – an entity tag for the currentGio.File
, orNone
to ignoreflags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first.
For more details, see
Gio.File.replace
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.replace_finish
() to get the result of the operation.
- do_replace_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
a
Gio.FileOutputStream
, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file replace operation started with
Gio.File.replace_async
().
- do_replace_readwrite(etag, make_backup, flags, cancellable) virtual¶
- Parameters:
etag (
str
orNone
) – an optional entity tag for the currentGio.File
, orNone
to ignoreflags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
a
Gio.FileIOStream
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Returns an output stream for overwriting the file in readwrite mode, possibly creating a backup copy of the file first. If the file doesn’t exist, it will be created.
For details about the behaviour, see
Gio.File.replace
() which does the same thing but returns an output stream only.Note that in many non-local file cases read and write streams are not supported, so make sure you really need to do read and write streaming, rather than just opening for reading or writing.
New in version 2.22.
- do_replace_readwrite_async(etag, make_backup, flags, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
etag (
str
orNone
) – an entity tag for the currentGio.File
, orNone
to ignoreflags (
Gio.FileCreateFlags
) – a set ofGio.FileCreateFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously overwrites the file in read-write mode, replacing the contents, possibly creating a backup copy of the file first.
For more details, see
Gio.File.replace_readwrite
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.replace_readwrite_finish
() to get the result of the operation.New in version 2.22.
- do_replace_readwrite_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
a
Gio.FileIOStream
, orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes an asynchronous file replace operation started with
Gio.File.replace_readwrite_async
().New in version 2.22.
- do_resolve_relative_path(relative_path) virtual¶
- Parameters:
relative_path (
str
) – a given relative path string- Returns:
a
Gio.File
for the resolved path.- Return type:
Resolves a relative path for file to an absolute path.
This call does no blocking I/O.
If the relative_path is an absolute path name, the resolution is done absolutely (without taking file path as base).
- do_set_attribute(attribute, type, value_p, flags, cancellable) virtual¶
- Parameters:
attribute (
str
) – a string containing the attribute’s nametype (
Gio.FileAttributeType
) – The type of the attributevalue_p (
object
orNone
) – a pointer to the value (or the pointer itself if the type is a pointer type)flags (
Gio.FileQueryInfoFlags
) – a set ofGio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
- Return type:
Sets an attribute in the file with attribute name attribute to value_p.
Some attributes can be unset by setting type to
Gio.FileAttributeType.INVALID
and value_p toNone
.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 errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_set_attributes_async(info, flags, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
info (
Gio.FileInfo
) – aGio.FileInfo
flags (
Gio.FileQueryInfoFlags
) – aGio.FileQueryInfoFlags
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously sets the attributes of file with info.
For more details, see
Gio.File.set_attributes_from_info
(), which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.set_attributes_finish
() to get the result of the operation.
- do_set_attributes_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
True
if the attributes were set correctly,False
otherwise.- info:
- Return type:
(
bool
, info:Gio.FileInfo
)
Finishes setting an attribute started in
Gio.File.set_attributes_async
().
- do_set_attributes_from_info(info, flags, cancellable) virtual¶
- Parameters:
info (
Gio.FileInfo
) – aGio.FileInfo
flags (
Gio.FileQueryInfoFlags
) –Gio.FileQueryInfoFlags
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
- Return type:
Tries to set all attributes in the
Gio.FileInfo
on the target values, not stopping on the first error.If there is any error during this operation then error will be set to the first error. Error on particular fields are flagged by setting the “status” field in the attribute value to
Gio.FileAttributeStatus.ERROR_SETTING
, which means you can also detect further errors.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_set_display_name(display_name, cancellable) virtual¶
- Parameters:
display_name (
str
) – a stringcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore
- Returns:
a
Gio.File
specifying what file was renamed to, orNone
if there was an error. Free the returned object withGObject.Object.unref
().- Return type:
Renames file to the specified display name.
The display name is converted from UTF-8 to the correct encoding for the target filesystem if possible and the file is renamed to this.
If you want to implement a rename operation in the user interface the edit name (
Gio.FILE_ATTRIBUTE_STANDARD_EDIT_NAME
) should be used as the initial value in the rename widget, and then the result after editing should be passed toGio.File.set_display_name
().On success the resulting converted filename is returned.
If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_set_display_name_async(display_name, io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
display_name (
str
) – a stringio_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously sets the display name for a given
Gio.File
.For more details, see
Gio.File.set_display_name
() which is the synchronous version of this call.When the operation is finished, callback will be called. You can then call
Gio.File.set_display_name_finish
() to get the result of the operation.
- do_set_display_name_finish(res) virtual¶
- Parameters:
res (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
a
Gio.File
orNone
on error. Free the returned object withGObject.Object.unref
().- Return type:
Finishes setting a display name started with
Gio.File.set_display_name_async
().
- do_start_mountable(flags, start_operation, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.DriveStartFlags
) – flags affecting the operationstart_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
, orNone
to avoid user interactioncancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied, orNone
user_data (
object
orNone
) – the data to pass to callback function
Starts a file of type
Gio.FileType.MOUNTABLE
. Using start_operation, you can request callbacks when, for instance, passwords are needed during authentication.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.mount_mountable_finish
() to get the result of the operation.New in version 2.22.
- do_start_mountable_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
True
if the operation finished successfully.False
otherwise.- Return type:
Finishes a start operation. See
Gio.File.start_mountable
() for details.Finish an asynchronous start operation that was started with
Gio.File.start_mountable
().New in version 2.22.
- do_stop_mountable(flags, mount_operation, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.MountUnmountFlags
) – flags affecting the operationmount_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
, orNone
to avoid user interaction.cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfied, orNone
user_data (
object
orNone
) – the data to pass to callback function
Stops a file of type
Gio.FileType.MOUNTABLE
.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.stop_mountable_finish
() to get the result of the operation.New in version 2.22.
- do_stop_mountable_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
True
if the operation finished successfully.False
otherwise.- Return type:
Finishes a stop operation, see
Gio.File.stop_mountable
() for details.Finish an asynchronous stop operation that was started with
Gio.File.stop_mountable
().New in version 2.22.
- do_trash(cancellable) virtual¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignore- Returns:
- Return type:
Sends file to the “Trashcan”, if possible. This is similar to deleting it, but the user can recover it before emptying the trashcan. Not all file systems support trashing, so this call can return the
Gio.IOErrorEnum.NOT_SUPPORTED
error. Since GLib 2.66, thex-gvfs-notrash
unix mount option can be used to disableGio.File.trash
() support for certain mounts, theGio.IOErrorEnum.NOT_SUPPORTED
error will be returned in that case.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.
- do_trash_async(io_priority, cancellable, callback, *user_data) virtual¶
- Parameters:
io_priority (
int
) – the I/O priority of the requestcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Asynchronously sends file to the Trash location, if possible.
New in version 2.38.
- do_trash_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
- Return type:
Finishes an asynchronous file trashing operation, started with
Gio.File.trash_async
().New in version 2.38.
- do_unmount_mountable(flags, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.MountUnmountFlags
) – flags affecting the operationcancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Unmounts a file of type
Gio.FileType.MOUNTABLE
.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.unmount_mountable_finish
() to get the result of the operation.Deprecated since version 2.22: Use
Gio.File.unmount_mountable_with_operation
() instead.
- do_unmount_mountable_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
True
if the operation finished successfully.False
otherwise.- Return type:
Finishes an unmount operation, see
Gio.File.unmount_mountable
() for details.Finish an asynchronous unmount operation that was started with
Gio.File.unmount_mountable
().Deprecated since version 2.22: Use
Gio.File.unmount_mountable_with_operation_finish
() instead.
- do_unmount_mountable_with_operation(flags, mount_operation, cancellable, callback, *user_data) virtual¶
- Parameters:
flags (
Gio.MountUnmountFlags
) – flags affecting the operationmount_operation (
Gio.MountOperation
orNone
) – aGio.MountOperation
, orNone
to avoid user interactioncancellable (
Gio.Cancellable
orNone
) – optionalGio.Cancellable
object,None
to ignorecallback (
Gio.AsyncReadyCallback
orNone
) – aGio.AsyncReadyCallback
to call when the request is satisfieduser_data (
object
orNone
) – the data to pass to callback function
Unmounts a file of type
Gio.FileType.MOUNTABLE
.If cancellable is not
None
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorGio.IOErrorEnum.CANCELLED
will be returned.When the operation is finished, callback will be called. You can then call
Gio.File.unmount_mountable_finish
() to get the result of the operation.New in version 2.22.
- do_unmount_mountable_with_operation_finish(result) virtual¶
- Parameters:
result (
Gio.AsyncResult
) – aGio.AsyncResult
- Returns:
True
if the operation finished successfully.False
otherwise.- Return type:
Finishes an unmount operation, see
Gio.File.unmount_mountable_with_operation
() for details.Finish an asynchronous unmount operation that was started with
Gio.File.unmount_mountable_with_operation
().New in version 2.22.