Package ch.bailu.gtk.gio
Class File
- All Implemented Interfaces:
PointerInterface
#GFile is a high level abstraction for manipulating files on a
virtual file system. #GFiles 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 #GInputStream and #GOutputStream).
To construct a #GFile, you can use:
- g_file_new_for_path() if you have a path.
- g_file_new_for_uri() if you have a URI.
- g_file_new_for_commandline_arg() for a command line argument.
- g_file_new_tmp() to create a temporary file from a template.
- g_file_new_tmp_async() to asynchronously create a temporary file.
- g_file_new_tmp_dir_async() to asynchronously create a temporary directory.
- g_file_parse_name() from a UTF-8 string gotten from g_file_get_parse_name().
- g_file_new_build_filename() 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
#GFiles are extensible it could also be something else that corresponds
to a pathname in a userspace implementation of a filesystem.
#GFiles 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 g_file_get_parent() to get an identifier for the parent
directory, g_file_get_child() to get a child within a directory,
g_file_resolve_relative_path() to resolve a relative path between two
#GFiles. There can be multiple hierarchies, so you may not end up at
the same root if you repeatedly call g_file_get_parent() on two different
files.
All #GFiles have a basename (get with g_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 g_file_query_info().
This is guaranteed to be in UTF-8 and can be used in a user interface.
But always store the real basename or the #GFile to use to actually
access the file, because there is no way to go from a display name to
the actual name.
Using #GFile as an identifier has the same weaknesses as using a path
in that there may be multiple aliases for the same file. For instance,
hard or soft links may cause two different #GFiles to refer to the same
file. Other possible causes for aliases are: case insensitive filesystems,
short and long names on FAT/NTFS, or bind mounts in Linux. If you want to
check if two #GFiles point to the same file you can query for the
%G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial
canonicalization of pathnames passed in, so that trivial differences in
the path string used at creation (duplicated slashes, slash at end of
path, "." or ".." path segments, etc) does not create different #GFiles.
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 #GAsyncReadyCallback which is then used to finalize
the operation, producing a GAsyncResult 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][async-programming] for
more.
Some #GFile operations almost always take a noticeable amount of time, and
so do not have synchronous analogs. Notable cases include:
- g_file_mount_mountable() to mount a mountable file.
- g_file_unmount_mountable_with_operation() to unmount a mountable file.
- g_file_eject_mountable_with_operation() to eject a mountable file.
## Entity Tags # {#gfile-etag}
One notable feature of #GFiles 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.
virtual file system. #GFiles 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 #GInputStream and #GOutputStream).
To construct a #GFile, you can use:
- g_file_new_for_path() if you have a path.
- g_file_new_for_uri() if you have a URI.
- g_file_new_for_commandline_arg() for a command line argument.
- g_file_new_tmp() to create a temporary file from a template.
- g_file_new_tmp_async() to asynchronously create a temporary file.
- g_file_new_tmp_dir_async() to asynchronously create a temporary directory.
- g_file_parse_name() from a UTF-8 string gotten from g_file_get_parse_name().
- g_file_new_build_filename() 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
#GFiles are extensible it could also be something else that corresponds
to a pathname in a userspace implementation of a filesystem.
#GFiles 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 g_file_get_parent() to get an identifier for the parent
directory, g_file_get_child() to get a child within a directory,
g_file_resolve_relative_path() to resolve a relative path between two
#GFiles. There can be multiple hierarchies, so you may not end up at
the same root if you repeatedly call g_file_get_parent() on two different
files.
All #GFiles have a basename (get with g_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 g_file_query_info().
This is guaranteed to be in UTF-8 and can be used in a user interface.
But always store the real basename or the #GFile to use to actually
access the file, because there is no way to go from a display name to
the actual name.
Using #GFile as an identifier has the same weaknesses as using a path
in that there may be multiple aliases for the same file. For instance,
hard or soft links may cause two different #GFiles to refer to the same
file. Other possible causes for aliases are: case insensitive filesystems,
short and long names on FAT/NTFS, or bind mounts in Linux. If you want to
check if two #GFiles point to the same file you can query for the
%G_FILE_ATTRIBUTE_ID_FILE attribute. Note that #GFile does some trivial
canonicalization of pathnames passed in, so that trivial differences in
the path string used at creation (duplicated slashes, slash at end of
path, "." or ".." path segments, etc) does not create different #GFiles.
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 #GAsyncReadyCallback which is then used to finalize
the operation, producing a GAsyncResult 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][async-programming] for
more.
Some #GFile operations almost always take a noticeable amount of time, and
so do not have synchronous analogs. Notable cases include:
- g_file_mount_mountable() to mount a mountable file.
- g_file_unmount_mountable_with_operation() to unmount a mountable file.
- g_file_eject_mountable_with_operation() to eject a mountable file.
## Entity Tags # {#gfile-etag}
One notable feature of #GFiles 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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionappendTo
(int flags, Cancellable cancellable) Gets an output stream for appending data to the file.void
appendToAsync
(int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously opens @file for appending.Finishes an asynchronous file append operation started with
g_file_append_to_async().buildAttributeListForCopy
(int flags, Cancellable cancellable) Prepares the file attribute query string for copying to @file.boolean
copyAttributes
(File destination, int flags, Cancellable cancellable) Copies the file attributes from @source to @destination.boolean
copyFinish
(AsyncResult res) Finishes copying the file started with g_file_copy_async().create
(int flags, Cancellable cancellable) Creates a new file and returns an output stream for writing to it.void
createAsync
(int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously creates a new file and returns an output stream
for writing to it.createFinish
(AsyncResult res) Finishes an asynchronous file create operation started with
g_file_create_async().createReadwrite
(int flags, Cancellable cancellable) Creates a new file and returns a stream for reading and
writing to it.void
createReadwriteAsync
(int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously creates a new file and returns a stream
for reading and writing to it.Finishes an asynchronous file create operation started with
g_file_create_readwrite_async().boolean
delete
(Cancellable cancellable) Deletes a file.void
deleteAsync
(int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously delete a file.boolean
deleteFinish
(AsyncResult result) Finishes deleting a file started with g_file_delete_async().dup()
Duplicates a #GFile handle.void
ejectMountableWithOperation
(int flags, MountOperation mount_operation, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Starts an asynchronous eject on a mountable.boolean
Finishes an asynchronous eject operation started by
g_file_eject_mountable_with_operation().enumerateChildren
(Str attributes, int flags, Cancellable cancellable) Gets the requested information about the files in a directory.enumerateChildren
(String attributes, int flags, Cancellable cancellable) Gets the requested information about the files in a directory.void
enumerateChildrenAsync
(Str attributes, int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously gets the requested information about the files
in a directory.void
enumerateChildrenAsync
(String attributes, int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously gets the requested information about the files
in a directory.Finishes an async enumerate children operation.boolean
Checks if the two given #GFiles refer to the same file.findEnclosingMount
(Cancellable cancellable) Gets a #GMount for the #GFile.void
findEnclosingMountAsync
(int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously gets the mount for the file.Finishes an asynchronous find mount request.Gets the base name (the last component of the path) for a given #GFile.Gets a child of @file with basename equal to @name.Gets a child of @file with basename equal to @name.getChildForDisplayName
(Str display_name) Gets the child of @file for a given @display_name (i.e. a UTF-8
version of the name).getChildForDisplayName
(String display_name) Gets the child of @file for a given @display_name (i.e. a UTF-8
version of the name).static ClassHandler
static int
Gets the parent directory for the @file.static long
static TypeSystem.TypeSize
Gets the parse name of the @file.getPath()
Gets the local pathname for #GFile, if one exists.getRelativePath
(File descendant) Gets the path for @descendant relative to @parent.static long
static TypeSystem.TypeSize
getUri()
Gets the URI for the @file.Gets the URI scheme for a #GFile.int
hash()
Creates a hash value for a #GFile.boolean
Checks if @file has a parent, and optionally, if it is @parent.boolean
Checks whether @file has the prefix specified by @prefix.boolean
hasUriScheme
(Str uri_scheme) Checks to see if a #GFile has a given URI scheme.boolean
hasUriScheme
(String uri_scheme) Checks to see if a #GFile has a given URI scheme.boolean
isNative()
Checks to see if a file is native to the platform.void
loadBytesAsync
(Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously loads the contents of @file as #GBytes.boolean
loadContents
(Cancellable cancellable, Strs contents, Int64 length, Strs etag_out) Loads the content of the file into memory.void
loadContentsAsync
(Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Starts an asynchronous load of the @file's contents.boolean
loadContentsFinish
(AsyncResult res, Strs contents, Int64 length, Strs etag_out) Finishes an asynchronous load of the @file's contents.boolean
loadPartialContentsFinish
(AsyncResult res, Strs contents, Int64 length, Strs etag_out) Finishes an asynchronous partial load operation that was started
with g_file_load_partial_contents_async().boolean
makeDirectory
(Cancellable cancellable) Creates a directory.void
makeDirectoryAsync
(int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously creates a directory.boolean
makeDirectoryFinish
(AsyncResult result) Finishes an asynchronous directory creation, started with
g_file_make_directory_async().boolean
makeDirectoryWithParents
(Cancellable cancellable) Creates a directory and any parent directories that may not
exist similar to 'mkdir -p'.boolean
makeSymbolicLink
(Str symlink_value, Cancellable cancellable) Creates a symbolic link named @file which contains the string
@symlink_value.boolean
makeSymbolicLink
(String symlink_value, Cancellable cancellable) Creates a symbolic link named @file which contains the string
@symlink_value.void
makeSymbolicLinkAsync
(Str symlink_value, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously creates a symbolic link named @file which contains the
string @symlink_value.void
makeSymbolicLinkAsync
(String symlink_value, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously creates a symbolic link named @file which contains the
string @symlink_value.boolean
makeSymbolicLinkFinish
(AsyncResult result) Finishes an asynchronous symbolic link creation, started with
g_file_make_symbolic_link_async().void
measureDiskUsageAsync
(int flags, int io_priority, Cancellable cancellable, File.OnFileMeasureProgressCallback progress_callback, Pointer progress_data, File.OnAsyncReadyCallback callback, Pointer user_data) Recursively measures the disk usage of @file.monitor
(int flags, Cancellable cancellable) Obtains a file or directory monitor for the given file,
depending on the type of the file.monitorDirectory
(int flags, Cancellable cancellable) Obtains a directory monitor for the given file.monitorFile
(int flags, Cancellable cancellable) Obtains a file monitor for the given file.void
mountEnclosingVolume
(int flags, MountOperation mount_operation, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Starts a @mount_operation, mounting the volume that contains
the file @location.boolean
Finishes a mount operation started by g_file_mount_enclosing_volume().void
mountMountable
(int flags, MountOperation mount_operation, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Mounts a file of type G_FILE_TYPE_MOUNTABLE.mountMountableFinish
(AsyncResult result) Finishes a mount operation.boolean
moveFinish
(AsyncResult result) Finishes an asynchronous file movement, started with
g_file_move_async().static File
newBuildFilename
(Str first_element, Object... _elipse) Constructs a #GFile from a series of elements using the correct
separator for filenames.static File
newForCommandlineArg
(Str arg) Creates a #GFile with the given argument from the command line.static File
newForCommandlineArgAndCwd
(Str arg, Str cwd) Creates a #GFile with the given argument from the command line.static File
newForPath
(Str path) Constructs a #GFile for a given path.static File
Constructs a #GFile for a given URI.static void
newTmpAsync
(Str tmpl, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously opens a file in the preferred directory for temporary files
(as returned by g_get_tmp_dir()) as g_file_new_tmp().static void
newTmpDirAsync
(Str tmpl, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously creates a directory in the preferred directory for
temporary files (as returned by g_get_tmp_dir()) as g_dir_make_tmp().static File
newTmpDirFinish
(AsyncResult result) Finishes a temporary directory creation started by
g_file_new_tmp_dir_async().openReadwrite
(Cancellable cancellable) Opens an existing file for reading and writing.void
openReadwriteAsync
(int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously opens @file for reading and writing.Finishes an asynchronous file read operation started with
g_file_open_readwrite_async().static File
Constructs a #GFile with the given @parse_name (i.e. something
given by g_file_get_parse_name()).peekPath()
Exactly like g_file_get_path(), but caches the result via
g_object_set_qdata_full().void
pollMountable
(Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Polls a file of type %G_FILE_TYPE_MOUNTABLE.boolean
pollMountableFinish
(AsyncResult result) Finishes a poll operation.queryDefaultHandler
(Cancellable cancellable) Returns the #GAppInfo that is registered as the default
application to handle the file specified by @file.void
queryDefaultHandlerAsync
(int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Async version of g_file_query_default_handler().queryDefaultHandlerFinish
(AsyncResult result) Finishes a g_file_query_default_handler_async() operation.boolean
queryExists
(Cancellable cancellable) Utility function to check if a particular file exists.queryFilesystemInfo
(Str attributes, Cancellable cancellable) Similar to g_file_query_info(), but obtains information
about the filesystem the @file is on, rather than the file itself.queryFilesystemInfo
(String attributes, Cancellable cancellable) Similar to g_file_query_info(), but obtains information
about the filesystem the @file is on, rather than the file itself.void
queryFilesystemInfoAsync
(Str attributes, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously gets the requested information about the filesystem
that the specified @file is on.void
queryFilesystemInfoAsync
(String attributes, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously gets the requested information about the filesystem
that the specified @file is on.Finishes an asynchronous filesystem info query.int
queryFileType
(int flags, Cancellable cancellable) Utility function to inspect the #GFileType of a file.queryInfo
(Str attributes, int flags, Cancellable cancellable) Gets the requested information about specified @file.queryInfo
(String attributes, int flags, Cancellable cancellable) Gets the requested information about specified @file.void
queryInfoAsync
(Str attributes, int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously gets the requested information about specified @file.void
queryInfoAsync
(String attributes, int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously gets the requested information about specified @file.Finishes an asynchronous file info query.querySettableAttributes
(Cancellable cancellable) Obtain the list of settable attributes for the file.queryWritableNamespaces
(Cancellable cancellable) Obtain the list of attribute namespaces where new attributes
can be created by a user.read
(Cancellable cancellable) Opens a file for reading.void
readAsync
(int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously opens @file for reading.readFinish
(AsyncResult res) Finishes an asynchronous file read operation started with
g_file_read_async().replace
(Str etag, boolean make_backup, int flags, Cancellable cancellable) Returns an output stream for overwriting the file, possibly
creating a backup copy of the file first.replace
(String etag, boolean make_backup, int flags, Cancellable cancellable) Returns an output stream for overwriting the file, possibly
creating a backup copy of the file first.void
replaceAsync
(Str etag, boolean make_backup, int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously overwrites the file, replacing the contents,
possibly creating a backup copy of the file first.void
replaceAsync
(String etag, boolean make_backup, int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously overwrites the file, replacing the contents,
possibly creating a backup copy of the file first.boolean
replaceContents
(Str contents, long length, Str etag, boolean make_backup, int flags, Strs new_etag, Cancellable cancellable) Replaces the contents of @file with @contents of @length bytes.boolean
replaceContents
(String contents, long length, String etag, boolean make_backup, int flags, Strs new_etag, Cancellable cancellable) Replaces the contents of @file with @contents of @length bytes.void
replaceContentsAsync
(Str contents, long length, Str etag, boolean make_backup, int flags, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Starts an asynchronous replacement of @file with the given
@contents of @length bytes.void
replaceContentsAsync
(String contents, long length, String etag, boolean make_backup, int flags, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Starts an asynchronous replacement of @file with the given
@contents of @length bytes.void
replaceContentsBytesAsync
(Bytes contents, Str etag, boolean make_backup, int flags, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Same as g_file_replace_contents_async() but takes a #GBytes input instead.void
replaceContentsBytesAsync
(Bytes contents, String etag, boolean make_backup, int flags, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Same as g_file_replace_contents_async() but takes a #GBytes input instead.boolean
replaceContentsFinish
(AsyncResult res, Strs new_etag) Finishes an asynchronous replace of the given @file.replaceFinish
(AsyncResult res) Finishes an asynchronous file replace operation started with
g_file_replace_async().replaceReadwrite
(Str etag, boolean make_backup, int flags, Cancellable cancellable) Returns an output stream for overwriting the file in readwrite mode,
possibly creating a backup copy of the file first.replaceReadwrite
(String etag, boolean make_backup, int flags, Cancellable cancellable) Returns an output stream for overwriting the file in readwrite mode,
possibly creating a backup copy of the file first.void
replaceReadwriteAsync
(Str etag, boolean make_backup, int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously overwrites the file in read-write mode,
replacing the contents, possibly creating a backup copy
of the file first.void
replaceReadwriteAsync
(String etag, boolean make_backup, int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously overwrites the file in read-write mode,
replacing the contents, possibly creating a backup copy
of the file first.Finishes an asynchronous file replace operation started with
g_file_replace_readwrite_async().resolveRelativePath
(Str relative_path) Resolves a relative path for @file to an absolute path.resolveRelativePath
(String relative_path) Resolves a relative path for @file to an absolute path.boolean
setAttribute
(Str attribute, int type, Pointer value_p, int flags, Cancellable cancellable) Sets an attribute in the file with attribute name @attribute to @value_p.boolean
setAttribute
(String attribute, int type, Pointer value_p, int flags, Cancellable cancellable) Sets an attribute in the file with attribute name @attribute to @value_p.boolean
setAttributeByteString
(Str attribute, Str value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.boolean
setAttributeByteString
(String attribute, String value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.boolean
setAttributeInt32
(Str attribute, int value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.boolean
setAttributeInt32
(String attribute, int value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.boolean
setAttributeInt64
(Str attribute, long value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.boolean
setAttributeInt64
(String attribute, long value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.void
setAttributesAsync
(FileInfo info, int flags, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously sets the attributes of @file with @info.boolean
setAttributesFromInfo
(FileInfo info, int flags, Cancellable cancellable) Tries to set all attributes in the #GFileInfo on the target
values, not stopping on the first error.boolean
setAttributeString
(Str attribute, Str value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.boolean
setAttributeString
(String attribute, String value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.boolean
setAttributeUint32
(Str attribute, int value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.boolean
setAttributeUint32
(String attribute, int value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.boolean
setAttributeUint64
(Str attribute, long value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.boolean
setAttributeUint64
(String attribute, long value, int flags, Cancellable cancellable) Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.setDisplayName
(Str display_name, Cancellable cancellable) Renames @file to the specified display name.setDisplayName
(String display_name, Cancellable cancellable) Renames @file to the specified display name.void
setDisplayNameAsync
(Str display_name, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously sets the display name for a given #GFile.void
setDisplayNameAsync
(String display_name, int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously sets the display name for a given #GFile.Finishes setting a display name started with
g_file_set_display_name_async().void
startMountable
(int flags, MountOperation start_operation, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Starts a file of type %G_FILE_TYPE_MOUNTABLE.boolean
startMountableFinish
(AsyncResult result) Finishes a start operation.void
stopMountable
(int flags, MountOperation mount_operation, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Stops a file of type %G_FILE_TYPE_MOUNTABLE.boolean
stopMountableFinish
(AsyncResult result) Finishes a stop operation, see g_file_stop_mountable() for details.boolean
Checks if @file supports
[thread-default contexts][g-main-context-push-thread-default-context].boolean
trash
(Cancellable cancellable) Sends @file to the "Trashcan", if possible.void
trashAsync
(int io_priority, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously sends @file to the Trash location, if possible.boolean
trashFinish
(AsyncResult result) Finishes an asynchronous file trashing operation, started with
g_file_trash_async().void
unmountMountableWithOperation
(int flags, MountOperation mount_operation, Cancellable cancellable, File.OnAsyncReadyCallback callback, Pointer user_data) Unmounts a file of type %G_FILE_TYPE_MOUNTABLE.boolean
Finishes an unmount operation,
see g_file_unmount_mountable_with_operation() for details.Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
File
-
-
Method Details
-
getClassHandler
-
appendTo
public FileOutputStream appendTo(int flags, @Nullable Cancellable cancellable) throws AllocationError 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 %G_FILE_CREATE_PRIVATE in @flags the file
will be made readable only to the current user, to the level that
is supported on the target filesystem.
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
Some file systems don't allow all file names, and may return an
%G_IO_ERROR_INVALID_FILENAME error. If the file is a directory the
%G_IO_ERROR_IS_DIRECTORY error will be returned. Other errors are
possible too, and depend on what kind of filesystem the file is on.- Parameters:
flags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileOutputStream, or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
appendToAsync
public void appendToAsync(int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously opens @file for appending.
For more details, see g_file_append_to() which is
the synchronous version of this call.
When the operation is finished, @callback will be called.
You can then call g_file_append_to_finish() to get the result
of the operation.- Parameters:
flags
- a set of #GFileCreateFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
appendToFinish
Finishes an asynchronous file append operation started with
g_file_append_to_async().- Parameters:
res
- #GAsyncResult- Returns:
- a valid #GFileOutputStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
buildAttributeListForCopy
public Str buildAttributeListForCopy(int flags, @Nullable Cancellable cancellable) throws AllocationError Prepares the file attribute query string for copying to @file.
This function prepares an attribute query string to be
passed to g_file_query_info() to get a list of attributes
normally copied with the file (see g_file_copy_attributes()
for the detailed description). This function is used by the
implementation of g_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).- Parameters:
flags
- a set of #GFileCopyFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- an attribute query string for g_file_query_info(), or %NULL if an error occurs.
- Throws:
AllocationError
-
copyAttributes
public boolean copyAttributes(@Nonnull File destination, int flags, @Nullable Cancellable cancellable) throws AllocationError Copies the file attributes from @source to @destination.
Normally only a subset of the file attributes are copied,
those that are copies in a normal file copy operation
(which for instance does not include e.g. owner). However
if %G_FILE_COPY_ALL_METADATA is specified in @flags, then
all the metadata that is possible to copy is copied. This
is useful when implementing move by copy + delete source.- Parameters:
destination
- a #GFile to copy attributes toflags
- a set of #GFileCopyFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the attributes were copied successfully, %FALSE otherwise.
- Throws:
AllocationError
-
copyFinish
Finishes copying the file started with g_file_copy_async().- Parameters:
res
- a #GAsyncResult- Returns:
- a %TRUE on success, %FALSE on error.
- Throws:
AllocationError
-
create
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 %G_FILE_CREATE_PRIVATE in @flags the file
will be made readable only to the current user, to the level
that is supported on the target filesystem.
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
If a file or directory with this name already exists the
%G_IO_ERROR_EXISTS error will be returned. Some file systems don't
allow all file names, and may return an %G_IO_ERROR_INVALID_FILENAME
error, and if the name is to long %G_IO_ERROR_FILENAME_TOO_LONG will
be returned. Other errors are possible too, and depend on what kind
of filesystem the file is on.- Parameters:
flags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileOutputStream for the newly created file, or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
createAsync
public void createAsync(int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously creates a new file and returns an output stream
for writing to it. The file must not already exist.
For more details, see g_file_create() which is
the synchronous version of this call.
When the operation is finished, @callback will be called.
You can then call g_file_create_finish() to get the result
of the operation.- Parameters:
flags
- a set of #GFileCreateFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
createFinish
Finishes an asynchronous file create operation started with
g_file_create_async().- Parameters:
res
- a #GAsyncResult- Returns:
- a #GFileOutputStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
createReadwrite
public FileIOStream createReadwrite(int flags, @Nullable Cancellable cancellable) throws AllocationError 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 %G_FILE_CREATE_PRIVATE in @flags the file
will be made readable only to the current user, to the level
that is supported on the target filesystem.
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
If a file or directory with this name already exists, the
%G_IO_ERROR_EXISTS error will be returned. Some file systems don't
allow all file names, and may return an %G_IO_ERROR_INVALID_FILENAME
error, and if the name is too long, %G_IO_ERROR_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.- Parameters:
flags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileIOStream for the newly created file, or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
createReadwriteAsync
public void createReadwriteAsync(int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) 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 g_file_create_readwrite() which is
the synchronous version of this call.
When the operation is finished, @callback will be called.
You can then call g_file_create_readwrite_finish() to get
the result of the operation.- Parameters:
flags
- a set of #GFileCreateFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
createReadwriteFinish
Finishes an asynchronous file create operation started with
g_file_create_readwrite_async().- Parameters:
res
- a #GAsyncResult- Returns:
- a #GFileIOStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
delete
Deletes a file. If the @file is a directory, it will only be
deleted if it is empty. This has the same semantics as g_unlink().
If @file doesn’t exist, %G_IO_ERROR_NOT_FOUND will be returned. This allows
for deletion to be implemented avoiding
[time-of-check to time-of-use races](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use):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 %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the file was deleted. %FALSE otherwise.
- Throws:
AllocationError
-
deleteAsync
public void deleteAsync(int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) 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
g_unlink().- Parameters:
io_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
deleteFinish
Finishes deleting a file started with g_file_delete_async().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE if the file was deleted. %FALSE otherwise.
- Throws:
AllocationError
-
dup
Duplicates a #GFile handle. This operation does not duplicate
the actual file or directory represented by the #GFile; see
g_file_copy() if attempting to copy a file.
g_file_dup() is useful when a second handle is needed to the same underlying
file, for use in a separate thread (#GFile is not thread-safe). For use
within the same thread, use g_object_ref() to increment the existing object’s
reference count.
This call does no blocking I/O.- Returns:
- a new #GFile that is a duplicate of the given #GFile.
-
ejectMountableWithOperation
public void ejectMountableWithOperation(int flags, @Nullable MountOperation mount_operation, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) 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
g_file_eject_mountable_with_operation_finish().
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
flags
- flags affecting the operationmount_operation
- a #GMountOperation, or %NULL to avoid user interactioncancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfied, or %NULLuser_data
- the data to pass to callback function
-
ejectMountableWithOperationFinish
public boolean ejectMountableWithOperationFinish(@Nonnull AsyncResult result) throws AllocationError Finishes an asynchronous eject operation started by
g_file_eject_mountable_with_operation().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE if the @file was ejected successfully. %FALSE otherwise.
- Throws:
AllocationError
-
enumerateChildren
public FileEnumerator enumerateChildren(@Nonnull Str attributes, int flags, @Nullable Cancellable cancellable) throws AllocationError Gets the requested information about the files in a directory.
The result is a #GFileEnumerator object that will give out
#GFileInfo 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
%G_FILE_ATTRIBUTE_STANDARD_NAME. %G_FILE_ATTRIBUTE_STANDARD_NAME should
always be specified if you plan to call g_file_enumerator_get_child() or
g_file_enumerator_iterate() on the returned enumerator.
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
be returned. If the file is not a directory, the %G_IO_ERROR_NOT_DIRECTORY
error will be returned. Other errors are possible too.- Parameters:
attributes
- an attribute query stringflags
- a set of #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- A #GFileEnumerator if successful, %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
enumerateChildren
public FileEnumerator enumerateChildren(String attributes, int flags, @Nullable Cancellable cancellable) throws AllocationError Gets the requested information about the files in a directory.
The result is a #GFileEnumerator object that will give out
#GFileInfo 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
%G_FILE_ATTRIBUTE_STANDARD_NAME. %G_FILE_ATTRIBUTE_STANDARD_NAME should
always be specified if you plan to call g_file_enumerator_get_child() or
g_file_enumerator_iterate() on the returned enumerator.
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
be returned. If the file is not a directory, the %G_IO_ERROR_NOT_DIRECTORY
error will be returned. Other errors are possible too.- Parameters:
attributes
- an attribute query stringflags
- a set of #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- A #GFileEnumerator if successful, %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
enumerateChildrenAsync
public void enumerateChildrenAsync(@Nonnull Str attributes, int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously gets the requested information about the files
in a directory. The result is a #GFileEnumerator object that will
give out #GFileInfo objects for all the files in the directory.
For more details, see g_file_enumerate_children() which is
the synchronous version of this call.
When the operation is finished, @callback will be called. You can
then call g_file_enumerate_children_finish() to get the result of
the operation.- Parameters:
attributes
- an attribute query stringflags
- a set of #GFileQueryInfoFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
enumerateChildrenAsync
public void enumerateChildrenAsync(String attributes, int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously gets the requested information about the files
in a directory. The result is a #GFileEnumerator object that will
give out #GFileInfo objects for all the files in the directory.
For more details, see g_file_enumerate_children() which is
the synchronous version of this call.
When the operation is finished, @callback will be called. You can
then call g_file_enumerate_children_finish() to get the result of
the operation.- Parameters:
attributes
- an attribute query stringflags
- a set of #GFileQueryInfoFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
enumerateChildrenFinish
Finishes an async enumerate children operation.
See g_file_enumerate_children_async().- Parameters:
res
- a #GAsyncResult- Returns:
- a #GFileEnumerator or %NULL if an error occurred. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
equal
Checks if the two given #GFiles refer to the same file.
Note that two #GFiles 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.- Parameters:
file2
- the second #GFile- Returns:
- %TRUE if @file1 and @file2 are equal.
-
findEnclosingMount
Gets a #GMount for the #GFile.
#GMount is returned only for user interesting locations, see
#GVolumeMonitor. If the #GFileIface for @file does not have a #mount,
@error will be set to %G_IO_ERROR_NOT_FOUND and %NULL #will be returned.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GMount where the @file is located or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
findEnclosingMountAsync
public void findEnclosingMountAsync(int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously gets the mount for the file.
For more details, see g_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 g_file_find_enclosing_mount_finish() to
get the result of the operation.- Parameters:
io_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
findEnclosingMountFinish
Finishes an asynchronous find mount request.
See g_file_find_enclosing_mount_async().- Parameters:
res
- a #GAsyncResult- Returns:
- #GMount for given @file or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
getBasename
Gets the base name (the last component of the path) for a given #GFile.
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 %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
attribute with g_file_query_info().
This call does no blocking I/O.- Returns:
- string containing the #GFile's base name, or %NULL if given #GFile is invalid. The returned string should be freed with g_free() when no longer needed.
-
getChild
Gets a child of @file with basename equal to @name.
Note that the file with that specific name might not exist, but
you can still have a #GFile that points to it. You can use this
for instance to create that file.
This call does no blocking I/O.- Parameters:
name
- string containing the child's basename- Returns:
- a #GFile to a child specified by @name. Free the returned object with g_object_unref().
-
getChild
Gets a child of @file with basename equal to @name.
Note that the file with that specific name might not exist, but
you can still have a #GFile that points to it. You can use this
for instance to create that file.
This call does no blocking I/O.- Parameters:
name
- string containing the child's basename- Returns:
- a #GFile to a child specified by @name. Free the returned object with g_object_unref().
-
getChildForDisplayName
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 %NULL
and @error will be set. This is very useful when constructing a
#GFile for a new file and the user entered the filename in the
user interface, for instance when you select a directory and
type a filename in the file selector.
This call does no blocking I/O.- Parameters:
display_name
- string to a possible child- Returns:
- a #GFile to the specified child, or %NULL if the display name couldn't be converted. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
getChildForDisplayName
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 %NULL
and @error will be set. This is very useful when constructing a
#GFile for a new file and the user entered the filename in the
user interface, for instance when you select a directory and
type a filename in the file selector.
This call does no blocking I/O.- Parameters:
display_name
- string to a possible child- Returns:
- a #GFile to the specified child, or %NULL if the display name couldn't be converted. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
getParent
Gets the parent directory for the @file.
If the @file represents the root directory of the
file system, then %NULL will be returned.
This call does no blocking I/O.- Returns:
- a #GFile structure to the parent of the given #GFile or %NULL if there is no parent. Free the returned object with g_object_unref().
-
getParseName
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 #GFile back using
g_file_parse_name().
This is generally used to show the #GFile 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.- Returns:
- a string containing the #GFile's parse name. The returned string should be freed with g_free() when no longer needed.
-
getPath
Gets the local pathname for #GFile, if one exists. If non-%NULL, this is
guaranteed to be an absolute, canonical path. It might contain symlinks.
This call does no blocking I/O.- Returns:
- string containing the #GFile's path, or %NULL if no such path exists. The returned string should be freed with g_free() when no longer needed.
-
getRelativePath
Gets the path for @descendant relative to @parent.
This call does no blocking I/O.- Parameters:
descendant
- input #GFile- Returns:
- string with the relative path from @descendant to @parent, or %NULL if @descendant doesn't have @parent as prefix. The returned string should be freed with g_free() when no longer needed.
-
getUri
Gets the URI for the @file.
This call does no blocking I/O.- Returns:
- a string containing the #GFile's URI. If the #GFile was constructed with an invalid URI, an invalid URI is returned. The returned string should be freed with g_free() when no longer needed.
-
getUriScheme
Gets the URI scheme for a #GFile.
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 #GFile,
in that it might be replaced with one that is logically equivalent to the #GFile.
This call does no blocking I/O.- Returns:
- a string containing the URI scheme for the given #GFile or %NULL if the #GFile was constructed with an invalid URI. The returned string should be freed with g_free() when no longer needed.
-
hasParent
Checks if @file has a parent, and optionally, if it is @parent.
If @parent is %NULL then this function returns %TRUE if @file has any
parent at all. If @parent is non-%NULL then %TRUE is only returned
if @file is an immediate child of @parent.- Parameters:
parent
- the parent to check for, or %NULL- Returns:
- %TRUE if @file is an immediate child of @parent (or any parent in the case that @parent is %NULL).
-
hasPrefix
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 #GFile is not a prefix of itself. If you want to check for
equality, use g_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.- Parameters:
prefix
- input #GFile- Returns:
- %TRUE if the @file's parent, grandparent, etc is @prefix, %FALSE otherwise.
-
hasUriScheme
Checks to see if a #GFile has a given URI scheme.
This call does no blocking I/O.- Parameters:
uri_scheme
- a string containing a URI scheme- Returns:
- %TRUE if #GFile's backend supports the given URI scheme, %FALSE if URI scheme is %NULL, not supported, or #GFile is invalid.
-
hasUriScheme
Checks to see if a #GFile has a given URI scheme.
This call does no blocking I/O.- Parameters:
uri_scheme
- a string containing a URI scheme- Returns:
- %TRUE if #GFile's backend supports the given URI scheme, %FALSE if URI scheme is %NULL, not supported, or #GFile is invalid.
-
hash
public int hash()Creates a hash value for a #GFile.
This call does no blocking I/O.- Returns:
- 0 if @file is not a valid #GFile, otherwise an integer that can be used as hash value for the #GFile. This function is intended for easily hashing a #GFile to add to a #GHashTable or similar data structure.
-
isNative
public boolean isNative()Checks to see if a file is native to the platform.
A native file is one expressed in the platform-native filename format,
e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local,
as it might be on a locally mounted remote filesystem.
On some systems non-native files may be available using the native
filesystem via a userspace filesystem (FUSE), in these cases this call
will return %FALSE, but g_file_get_path() will still return a native path.
This call does no blocking I/O.- Returns:
- %TRUE if @file is native
-
loadBytesAsync
public void loadBytesAsync(@Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously loads the contents of @file as #GBytes.
If @file is a resource:// based URI, the resulting bytes will reference the
embedded resource instead of a copy. Otherwise, this is equivalent to calling
g_file_load_contents_async() and g_bytes_new_take().
@callback should call g_file_load_bytes_finish() to get the result of this
asynchronous operation.
See g_file_load_bytes() for more information.- Parameters:
cancellable
- a #GCancellable or %NULLcallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
loadContents
public boolean loadContents(@Nullable Cancellable cancellable, @Nonnull Strs contents, @Nullable Int64 length, @Nullable Strs etag_out) throws AllocationError 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 g_free() when no longer
needed.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignorecontents
- a location to place the contents of the filelength
- a location to place the length of the contents of the file, or %NULL if the length is not neededetag_out
- a location to place the current entity tag for the file, or %NULL if the entity tag is not needed- Returns:
- %TRUE if the @file's contents were successfully loaded. %FALSE if there were errors.
- Throws:
AllocationError
-
loadContentsAsync
public void loadContentsAsync(@Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Starts an asynchronous load of the @file's contents.
For more details, see g_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
g_file_load_contents_finish() with the #GAsyncResult returned by
the @callback.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
loadContentsFinish
public boolean loadContentsFinish(@Nonnull AsyncResult res, @Nonnull Strs contents, @Nullable Int64 length, @Nullable Strs etag_out) throws AllocationError Finishes an asynchronous load of the @file'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
g_free() when no longer needed. If @etag_out is present, it will be
set to the new entity tag for the @file.- Parameters:
res
- a #GAsyncResultcontents
- a location to place the contents of the filelength
- a location to place the length of the contents of the file, or %NULL if the length is not neededetag_out
- a location to place the current entity tag for the file, or %NULL if the entity tag is not needed- Returns:
- %TRUE if the load was successful. If %FALSE and @error is present, it will be set appropriately.
- Throws:
AllocationError
-
loadPartialContentsFinish
public boolean loadPartialContentsFinish(@Nonnull AsyncResult res, @Nonnull Strs contents, @Nullable Int64 length, @Nullable Strs etag_out) throws AllocationError 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 g_free() when no longer
needed.- Parameters:
res
- a #GAsyncResultcontents
- a location to place the contents of the filelength
- a location to place the length of the contents of the file, or %NULL if the length is not neededetag_out
- a location to place the current entity tag for the file, or %NULL if the entity tag is not needed- Returns:
- %TRUE if the load was successful. If %FALSE and @error is present, it will be set appropriately.
- Throws:
AllocationError
-
makeDirectory
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 #GFile.
To recursively create directories, see g_file_make_directory_with_parents().
This function will fail if the parent directory does not exist, setting
@error to %G_IO_ERROR_NOT_FOUND. If the file system doesn't support
creating directories, this function will fail, setting @error to
%G_IO_ERROR_NOT_SUPPORTED.
For a local #GFile the newly created directory will have the default
(current) ownership and permissions of the current process.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE on successful creation, %FALSE otherwise.
- Throws:
AllocationError
-
makeDirectoryAsync
public void makeDirectoryAsync(int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously creates a directory.- Parameters:
io_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
makeDirectoryFinish
Finishes an asynchronous directory creation, started with
g_file_make_directory_async().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE on successful directory creation, %FALSE otherwise.
- Throws:
AllocationError
-
makeDirectoryWithParents
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
%G_IO_ERROR_NOT_SUPPORTED. If the directory itself already exists,
this function will fail setting @error to %G_IO_ERROR_EXISTS, unlike
the similar g_mkdir_with_parents().
For a local #GFile the newly created directories will have the default
(current) ownership and permissions of the current process.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if all directories have been successfully created, %FALSE otherwise.
- Throws:
AllocationError
-
makeSymbolicLink
public boolean makeSymbolicLink(@Nonnull Str symlink_value, @Nullable Cancellable cancellable) throws AllocationError Creates a symbolic link named @file which contains the string
@symlink_value.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
symlink_value
- a string with the path for the target of the new symlinkcancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE on the creation of a new symlink, %FALSE otherwise.
- Throws:
AllocationError
-
makeSymbolicLink
public boolean makeSymbolicLink(String symlink_value, @Nullable Cancellable cancellable) throws AllocationError Creates a symbolic link named @file which contains the string
@symlink_value.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
symlink_value
- a string with the path for the target of the new symlinkcancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE on the creation of a new symlink, %FALSE otherwise.
- Throws:
AllocationError
-
makeSymbolicLinkAsync
public void makeSymbolicLinkAsync(@Nonnull Str symlink_value, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously creates a symbolic link named @file which contains the
string @symlink_value.- Parameters:
symlink_value
- a string with the path for the target of the new symlinkio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
makeSymbolicLinkAsync
public void makeSymbolicLinkAsync(String symlink_value, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously creates a symbolic link named @file which contains the
string @symlink_value.- Parameters:
symlink_value
- a string with the path for the target of the new symlinkio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
makeSymbolicLinkFinish
Finishes an asynchronous symbolic link creation, started with
g_file_make_symbolic_link_async().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE on successful directory creation, %FALSE otherwise.
- Throws:
AllocationError
-
measureDiskUsageAsync
public void measureDiskUsageAsync(int flags, int io_priority, @Nullable Cancellable cancellable, File.OnFileMeasureProgressCallback progress_callback, @Nullable Pointer progress_data, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Recursively measures the disk usage of @file.
This is the asynchronous version of g_file_measure_disk_usage(). See
there for more information.- Parameters:
flags
- #GFileMeasureFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellableprogress_callback
- a #GFileMeasureProgressCallbackprogress_data
- user_data for @progress_callbackcallback
- a #GAsyncReadyCallback to call when completeuser_data
- the data to pass to callback function
-
monitor
Obtains a file or directory monitor for the given file,
depending on the type of the file.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
flags
- a set of #GFileMonitorFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileMonitor for the given @file, or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
monitorDirectory
public FileMonitor monitorDirectory(int flags, @Nullable Cancellable cancellable) throws AllocationError Obtains a directory monitor for the given file.
This may fail if directory monitoring is not supported.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
It does not make sense for @flags to contain
%G_FILE_MONITOR_WATCH_HARD_LINKS, since hard links can not be made to
directories. It is not possible to monitor all the files in a
directory for changes made via hard links; if you want to do this then
you must register individual watches with g_file_monitor().- Parameters:
flags
- a set of #GFileMonitorFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileMonitor for the given @file, or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
monitorFile
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 %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
If @flags contains %G_FILE_MONITOR_WATCH_HARD_LINKS then the monitor
will also attempt to report changes made to the file via another
filename (ie, a hard link). Without this flag, you can only rely on
changes made through the filename contained in @file to be
reported. Using this flag may result in an increase in resource
usage, and may not have any effect depending on the #GFileMonitor
backend and/or filesystem type.- Parameters:
flags
- a set of #GFileMonitorFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileMonitor for the given @file, or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
mountEnclosingVolume
public void mountEnclosingVolume(int flags, @Nullable MountOperation mount_operation, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) 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
g_file_mount_enclosing_volume_finish().
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
flags
- flags affecting the operationmount_operation
- a #GMountOperation or %NULL to avoid user interactioncancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfied, or %NULLuser_data
- the data to pass to callback function
-
mountEnclosingVolumeFinish
Finishes a mount operation started by g_file_mount_enclosing_volume().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE if successful. If an error has occurred, this function will return %FALSE and set @error appropriately if present.
- Throws:
AllocationError
-
mountMountable
public void mountMountable(int flags, @Nullable MountOperation mount_operation, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Mounts a file of type G_FILE_TYPE_MOUNTABLE.
Using @mount_operation, you can request callbacks when, for instance,
passwords are needed during authentication.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
When the operation is finished, @callback will be called.
You can then call g_file_mount_mountable_finish() to get
the result of the operation.- Parameters:
flags
- flags affecting the operationmount_operation
- a #GMountOperation, or %NULL to avoid user interactioncancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfied, or %NULLuser_data
- the data to pass to callback function
-
mountMountableFinish
Finishes a mount operation. See g_file_mount_mountable() for details.
Finish an asynchronous mount operation that was started
with g_file_mount_mountable().- Parameters:
result
- a #GAsyncResult- Returns:
- a #GFile or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
moveFinish
Finishes an asynchronous file movement, started with
g_file_move_async().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE on successful file move, %FALSE otherwise.
- Throws:
AllocationError
-
openReadwrite
Opens an existing file for reading and writing. The result is
a #GFileIOStream that can be used to read and write the contents
of the file.
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
be returned. If the file is a directory, the %G_IO_ERROR_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.- Parameters:
cancellable
- a #GCancellable- Returns:
- #GFileIOStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
openReadwriteAsync
public void openReadwriteAsync(int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously opens @file for reading and writing.
For more details, see g_file_open_readwrite() which is
the synchronous version of this call.
When the operation is finished, @callback will be called.
You can then call g_file_open_readwrite_finish() to get
the result of the operation.- Parameters:
io_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
openReadwriteFinish
Finishes an asynchronous file read operation started with
g_file_open_readwrite_async().- Parameters:
res
- a #GAsyncResult- Returns:
- a #GFileIOStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
peekPath
Exactly like g_file_get_path(), but caches the result via
g_object_set_qdata_full(). This is useful for example in C
applications which mix `g_file_*` APIs with native ones. It
also avoids an extra duplicated string when possible, so will be
generally more efficient.
This call does no blocking I/O.- Returns:
- string containing the #GFile's path, or %NULL if no such path exists. The returned string is owned by @file.
-
pollMountable
public void pollMountable(@Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Polls a file of type %G_FILE_TYPE_MOUNTABLE.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
When the operation is finished, @callback will be called.
You can then call g_file_mount_mountable_finish() to get
the result of the operation.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfied, or %NULLuser_data
- the data to pass to callback function
-
pollMountableFinish
Finishes a poll operation. See g_file_poll_mountable() for details.
Finish an asynchronous poll operation that was polled
with g_file_poll_mountable().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE if the operation finished successfully. %FALSE otherwise.
- Throws:
AllocationError
-
queryDefaultHandler
Returns the #GAppInfo that is registered as the default
application to handle the file specified by @file.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GAppInfo if the handle was found, %NULL if there were errors. When you are done with it, release it with g_object_unref()
- Throws:
AllocationError
-
queryDefaultHandlerAsync
public void queryDefaultHandlerAsync(int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Async version of g_file_query_default_handler().- Parameters:
io_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is doneuser_data
- data to pass to @callback
-
queryDefaultHandlerFinish
Finishes a g_file_query_default_handler_async() operation.- Parameters:
result
- a #GAsyncResult- Returns:
- a #GAppInfo if the handle was found, %NULL if there were errors. When you are done with it, release it with g_object_unref()
- Throws:
AllocationError
-
queryExists
Utility function to check if a particular file exists. This is
implemented using g_file_query_info() and as such does blocking I/O.
Note that in many cases it is [racy to first check for file existence](https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use)
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 g_file_create() which will either
atomically create the file or fail with a %G_IO_ERROR_EXISTS error.
However, in many cases an existence check is useful in a user interface,
for instance to make a menu item sensitive/insensitive, so that you don't
have to fool users that something is possible and then just show 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.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the file exists (and can be detected without error), %FALSE otherwise (or if cancelled).
-
queryFileType
Utility function to inspect the #GFileType of a file. This is
implemented using g_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.- Parameters:
flags
- a set of #GFileQueryInfoFlags passed to g_file_query_info()cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- The #GFileType of the file and %G_FILE_TYPE_UNKNOWN if the file does not exist
-
queryFilesystemInfo
public FileInfo queryFilesystemInfo(@Nonnull Str attributes, @Nullable Cancellable cancellable) throws AllocationError Similar to g_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
%G_FILE_ATTRIBUTE_FILESYSTEM_SIZE (the total size of the filesystem
in bytes), %G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of bytes available),
and %G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
be returned. Other errors are possible too, and depend on what
kind of filesystem the file is on.- Parameters:
attributes
- an attribute query stringcancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileInfo or %NULL if there was an error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
queryFilesystemInfo
public FileInfo queryFilesystemInfo(String attributes, @Nullable Cancellable cancellable) throws AllocationError Similar to g_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
%G_FILE_ATTRIBUTE_FILESYSTEM_SIZE (the total size of the filesystem
in bytes), %G_FILE_ATTRIBUTE_FILESYSTEM_FREE (number of bytes available),
and %G_FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will
be returned. Other errors are possible too, and depend on what
kind of filesystem the file is on.- Parameters:
attributes
- an attribute query stringcancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileInfo or %NULL if there was an error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
queryFilesystemInfoAsync
public void queryFilesystemInfoAsync(@Nonnull Str attributes, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously gets the requested information about the filesystem
that the specified @file is on. The result is a #GFileInfo object
that contains key-value attributes (such as type or size for the
file).
For more details, see g_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 g_file_query_info_finish() to get the result of the
operation.- Parameters:
attributes
- an attribute query stringio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
queryFilesystemInfoAsync
public void queryFilesystemInfoAsync(String attributes, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously gets the requested information about the filesystem
that the specified @file is on. The result is a #GFileInfo object
that contains key-value attributes (such as type or size for the
file).
For more details, see g_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 g_file_query_info_finish() to get the result of the
operation.- Parameters:
attributes
- an attribute query stringio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
queryFilesystemInfoFinish
Finishes an asynchronous filesystem info query.
See g_file_query_filesystem_info_async().- Parameters:
res
- a #GAsyncResult- Returns:
- #GFileInfo for given @file or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
queryInfo
public FileInfo queryInfo(@Nonnull Str attributes, int flags, @Nullable Cancellable cancellable) throws AllocationError Gets the requested information about specified @file.
The result is a #GFileInfo 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
%G_FILE_ATTRIBUTE_STANDARD_NAME.
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
For symlinks, normally the information about the target of the
symlink is returned, rather than information about the symlink
itself. However if you pass %G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
in @flags the information about the symlink itself will be returned.
Also, for symlinks that point to non-existing files the information
about the symlink itself will be returned.
If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be
returned. Other errors are possible too, and depend on what kind of
filesystem the file is on.- Parameters:
attributes
- an attribute query stringflags
- a set of #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileInfo for the given @file, or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
queryInfo
public FileInfo queryInfo(String attributes, int flags, @Nullable Cancellable cancellable) throws AllocationError Gets the requested information about specified @file.
The result is a #GFileInfo 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
%G_FILE_ATTRIBUTE_STANDARD_NAME.
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
For symlinks, normally the information about the target of the
symlink is returned, rather than information about the symlink
itself. However if you pass %G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
in @flags the information about the symlink itself will be returned.
Also, for symlinks that point to non-existing files the information
about the symlink itself will be returned.
If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be
returned. Other errors are possible too, and depend on what kind of
filesystem the file is on.- Parameters:
attributes
- an attribute query stringflags
- a set of #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileInfo for the given @file, or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
queryInfoAsync
public void queryInfoAsync(@Nonnull Str attributes, int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously gets the requested information about specified @file.
The result is a #GFileInfo object that contains key-value attributes
(such as type or size for the file).
For more details, see g_file_query_info() which is the synchronous
version of this call.
When the operation is finished, @callback will be called. You can
then call g_file_query_info_finish() to get the result of the operation.- Parameters:
attributes
- an attribute query stringflags
- a set of #GFileQueryInfoFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
queryInfoAsync
public void queryInfoAsync(String attributes, int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously gets the requested information about specified @file.
The result is a #GFileInfo object that contains key-value attributes
(such as type or size for the file).
For more details, see g_file_query_info() which is the synchronous
version of this call.
When the operation is finished, @callback will be called. You can
then call g_file_query_info_finish() to get the result of the operation.- Parameters:
attributes
- an attribute query stringflags
- a set of #GFileQueryInfoFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
queryInfoFinish
Finishes an asynchronous file info query.
See g_file_query_info_async().- Parameters:
res
- a #GAsyncResult- Returns:
- #GFileInfo for given @file or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
querySettableAttributes
public FileAttributeInfoList querySettableAttributes(@Nullable Cancellable cancellable) throws AllocationError 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 %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileAttributeInfoList describing the settable attributes. When you are done with it, release it with g_file_attribute_info_list_unref()
- Throws:
AllocationError
-
queryWritableNamespaces
public FileAttributeInfoList queryWritableNamespaces(@Nullable Cancellable cancellable) throws AllocationError 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 %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileAttributeInfoList describing the writable namespaces. When you are done with it, release it with g_file_attribute_info_list_unref()
- Throws:
AllocationError
-
read
Opens a file for reading. The result is a #GFileInputStream that
can be used to read the contents of the file.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
If the file does not exist, the %G_IO_ERROR_NOT_FOUND error will be
returned. If the file is a directory, the %G_IO_ERROR_IS_DIRECTORY
error will be returned. Other errors are possible too, and depend
on what kind of filesystem the file is on.- Parameters:
cancellable
- a #GCancellable- Returns:
- #GFileInputStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
readAsync
public void readAsync(int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously opens @file for reading.
For more details, see g_file_read() which is
the synchronous version of this call.
When the operation is finished, @callback will be called.
You can then call g_file_read_finish() to get the result
of the operation.- Parameters:
io_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
readFinish
Finishes an asynchronous file read operation started with
g_file_read_async().- Parameters:
res
- a #GAsyncResult- Returns:
- a #GFileInputStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
replace
public FileOutputStream replace(@Nullable Str etag, boolean make_backup, int flags, @Nullable Cancellable cancellable) throws AllocationError 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 %G_FILE_CREATE_PRIVATE in @flags the file
will be made readable only to the current user, to the level that
is supported on the target filesystem.
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
If you pass in a non-%NULL @etag value and @file already exists, then
this value is compared to the current entity tag of the file, and if
they differ an %G_IO_ERROR_WRONG_ETAG error is returned. This
generally means that the file has been changed since you last read
it. You can get the new etag from g_file_output_stream_get_etag()
after you've finished writing and closed the #GFileOutputStream. When
you load a new file you can use g_file_input_stream_query_info() to
get the etag of the file.
If @make_backup is %TRUE, this function will attempt to make a
backup of the current file before overwriting it. If this fails
a %G_IO_ERROR_CANT_CREATE_BACKUP error will be returned. If you
want to replace anyway, try again with @make_backup set to %FALSE.
If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will
be returned, and if the file is some other form of non-regular file
then a %G_IO_ERROR_NOT_REGULAR_FILE error will be returned. Some
file systems don't allow all file names, and may return an
%G_IO_ERROR_INVALID_FILENAME error, and if the name is to long
%G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors are
possible too, and depend on what kind of filesystem the file is on.- Parameters:
etag
- an optional [entity tag][gfile-etag] for the current #GFile, or #NULL to ignoremake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileOutputStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
replace
public FileOutputStream replace(String etag, boolean make_backup, int flags, @Nullable Cancellable cancellable) throws AllocationError 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 %G_FILE_CREATE_PRIVATE in @flags the file
will be made readable only to the current user, to the level that
is supported on the target filesystem.
If @cancellable is not %NULL, then the operation can be cancelled
by triggering the cancellable object from another thread. If the
operation was cancelled, the error %G_IO_ERROR_CANCELLED will be
returned.
If you pass in a non-%NULL @etag value and @file already exists, then
this value is compared to the current entity tag of the file, and if
they differ an %G_IO_ERROR_WRONG_ETAG error is returned. This
generally means that the file has been changed since you last read
it. You can get the new etag from g_file_output_stream_get_etag()
after you've finished writing and closed the #GFileOutputStream. When
you load a new file you can use g_file_input_stream_query_info() to
get the etag of the file.
If @make_backup is %TRUE, this function will attempt to make a
backup of the current file before overwriting it. If this fails
a %G_IO_ERROR_CANT_CREATE_BACKUP error will be returned. If you
want to replace anyway, try again with @make_backup set to %FALSE.
If the file is a directory the %G_IO_ERROR_IS_DIRECTORY error will
be returned, and if the file is some other form of non-regular file
then a %G_IO_ERROR_NOT_REGULAR_FILE error will be returned. Some
file systems don't allow all file names, and may return an
%G_IO_ERROR_INVALID_FILENAME error, and if the name is to long
%G_IO_ERROR_FILENAME_TOO_LONG will be returned. Other errors are
possible too, and depend on what kind of filesystem the file is on.- Parameters:
etag
- an optional [entity tag][gfile-etag] for the current #GFile, or #NULL to ignoremake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileOutputStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
replaceAsync
public void replaceAsync(@Nullable Str etag, boolean make_backup, int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously overwrites the file, replacing the contents,
possibly creating a backup copy of the file first.
For more details, see g_file_replace() which is
the synchronous version of this call.
When the operation is finished, @callback will be called.
You can then call g_file_replace_finish() to get the result
of the operation.- Parameters:
etag
- an [entity tag][gfile-etag] for the current #GFile, or %NULL to ignoremake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
replaceAsync
public void replaceAsync(String etag, boolean make_backup, int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously overwrites the file, replacing the contents,
possibly creating a backup copy of the file first.
For more details, see g_file_replace() which is
the synchronous version of this call.
When the operation is finished, @callback will be called.
You can then call g_file_replace_finish() to get the result
of the operation.- Parameters:
etag
- an [entity tag][gfile-etag] for the current #GFile, or %NULL to ignoremake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
replaceContents
public boolean replaceContents(@Nonnull Str contents, long length, @Nullable Str etag, boolean make_backup, int flags, @Nullable Strs new_etag, @Nullable Cancellable cancellable) throws AllocationError Replaces the contents of @file with @contents of @length bytes.
If @etag is specified (not %NULL), any existing file must have that etag,
or the error %G_IO_ERROR_WRONG_ETAG will be returned.
If @make_backup is %TRUE, this function will attempt to make a backup
of @file. Internally, it uses g_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 %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_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.- Parameters:
contents
- a string containing the new contents for @filelength
- the length of @contents in bytesetag
- the old [entity-tag][gfile-etag] for the document, or %NULLmake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagsnew_etag
- a location to a new [entity tag][gfile-etag] for the document. This should be freed with g_free() when no longer needed, or %NULLcancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if successful. If an error has occurred, this function will return %FALSE and set @error appropriately if present.
- Throws:
AllocationError
-
replaceContents
public boolean replaceContents(String contents, long length, String etag, boolean make_backup, int flags, @Nullable Strs new_etag, @Nullable Cancellable cancellable) throws AllocationError Replaces the contents of @file with @contents of @length bytes.
If @etag is specified (not %NULL), any existing file must have that etag,
or the error %G_IO_ERROR_WRONG_ETAG will be returned.
If @make_backup is %TRUE, this function will attempt to make a backup
of @file. Internally, it uses g_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 %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_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.- Parameters:
contents
- a string containing the new contents for @filelength
- the length of @contents in bytesetag
- the old [entity-tag][gfile-etag] for the document, or %NULLmake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagsnew_etag
- a location to a new [entity tag][gfile-etag] for the document. This should be freed with g_free() when no longer needed, or %NULLcancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if successful. If an error has occurred, this function will return %FALSE and set @error appropriately if present.
- Throws:
AllocationError
-
replaceContentsAsync
public void replaceContentsAsync(@Nonnull Str contents, long length, @Nullable Str etag, boolean make_backup, int flags, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Starts an asynchronous replacement of @file 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
g_file_replace_contents_finish().
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
If @make_backup is %TRUE, this function will attempt to
make a backup of @file.
Note that no copy of @contents will be made, so it must stay valid
until @callback is called. See g_file_replace_contents_bytes_async()
for a #GBytes version that will automatically hold a reference to the
contents (without copying) for the duration of the call.- Parameters:
contents
- string of contents to replace the file withlength
- the length of @contents in bytesetag
- a new [entity tag][gfile-etag] for the @file, or %NULLmake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
replaceContentsAsync
public void replaceContentsAsync(String contents, long length, String etag, boolean make_backup, int flags, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Starts an asynchronous replacement of @file 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
g_file_replace_contents_finish().
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
If @make_backup is %TRUE, this function will attempt to
make a backup of @file.
Note that no copy of @contents will be made, so it must stay valid
until @callback is called. See g_file_replace_contents_bytes_async()
for a #GBytes version that will automatically hold a reference to the
contents (without copying) for the duration of the call.- Parameters:
contents
- string of contents to replace the file withlength
- the length of @contents in bytesetag
- a new [entity tag][gfile-etag] for the @file, or %NULLmake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
replaceContentsBytesAsync
public void replaceContentsBytesAsync(@Nonnull Bytes contents, @Nullable Str etag, boolean make_backup, int flags, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Same as g_file_replace_contents_async() but takes a #GBytes input instead.
This function will keep a ref on @contents until the operation is done.
Unlike g_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
g_file_replace_contents_finish().- Parameters:
contents
- a #GBytesetag
- a new [entity tag][gfile-etag] for the @file, or %NULLmake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
replaceContentsBytesAsync
public void replaceContentsBytesAsync(@Nonnull Bytes contents, String etag, boolean make_backup, int flags, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Same as g_file_replace_contents_async() but takes a #GBytes input instead.
This function will keep a ref on @contents until the operation is done.
Unlike g_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
g_file_replace_contents_finish().- Parameters:
contents
- a #GBytesetag
- a new [entity tag][gfile-etag] for the @file, or %NULLmake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
replaceContentsFinish
public boolean replaceContentsFinish(@Nonnull AsyncResult res, @Nullable Strs new_etag) throws AllocationError Finishes an asynchronous replace of the given @file. See
g_file_replace_contents_async(). Sets @new_etag to the new entity
tag for the document, if present.- Parameters:
res
- a #GAsyncResultnew_etag
- a location of a new [entity tag][gfile-etag] for the document. This should be freed with g_free() when it is no longer needed, or %NULL- Returns:
- %TRUE on success, %FALSE on failure.
- Throws:
AllocationError
-
replaceFinish
Finishes an asynchronous file replace operation started with
g_file_replace_async().- Parameters:
res
- a #GAsyncResult- Returns:
- a #GFileOutputStream, or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
replaceReadwrite
public FileIOStream replaceReadwrite(@Nullable Str etag, boolean make_backup, int flags, @Nullable Cancellable cancellable) throws AllocationError 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 g_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.- Parameters:
etag
- an optional [entity tag][gfile-etag] for the current #GFile, or #NULL to ignoremake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileIOStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
replaceReadwrite
public FileIOStream replaceReadwrite(String etag, boolean make_backup, int flags, @Nullable Cancellable cancellable) throws AllocationError 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 g_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.- Parameters:
etag
- an optional [entity tag][gfile-etag] for the current #GFile, or #NULL to ignoremake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFileIOStream or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
replaceReadwriteAsync
public void replaceReadwriteAsync(@Nullable Str etag, boolean make_backup, int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously overwrites the file in read-write mode,
replacing the contents, possibly creating a backup copy
of the file first.
For more details, see g_file_replace_readwrite() which is
the synchronous version of this call.
When the operation is finished, @callback will be called.
You can then call g_file_replace_readwrite_finish() to get
the result of the operation.- Parameters:
etag
- an [entity tag][gfile-etag] for the current #GFile, or %NULL to ignoremake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
replaceReadwriteAsync
public void replaceReadwriteAsync(String etag, boolean make_backup, int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously overwrites the file in read-write mode,
replacing the contents, possibly creating a backup copy
of the file first.
For more details, see g_file_replace_readwrite() which is
the synchronous version of this call.
When the operation is finished, @callback will be called.
You can then call g_file_replace_readwrite_finish() to get
the result of the operation.- Parameters:
etag
- an [entity tag][gfile-etag] for the current #GFile, or %NULL to ignoremake_backup
- %TRUE if a backup should be createdflags
- a set of #GFileCreateFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
replaceReadwriteFinish
Finishes an asynchronous file replace operation started with
g_file_replace_readwrite_async().- Parameters:
res
- a #GAsyncResult- Returns:
- a #GFileIOStream, or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
resolveRelativePath
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).- Parameters:
relative_path
- a given relative path string- Returns:
- a #GFile for the resolved path.
-
resolveRelativePath
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).- Parameters:
relative_path
- a given relative path string- Returns:
- a #GFile for the resolved path.
-
setAttribute
public boolean setAttribute(@Nonnull Str attribute, int type, @Nullable Pointer value_p, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets an attribute in the file with attribute name @attribute to @value_p.
Some attributes can be unset by setting @type to
%G_FILE_ATTRIBUTE_TYPE_INVALID and @value_p to %NULL.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's nametype
- The type of the attributevalue_p
- a pointer to the value (or the pointer itself if the type is a pointer type)flags
- a set of #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the attribute was set, %FALSE otherwise.
- Throws:
AllocationError
-
setAttribute
public boolean setAttribute(String attribute, int type, @Nullable Pointer value_p, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets an attribute in the file with attribute name @attribute to @value_p.
Some attributes can be unset by setting @type to
%G_FILE_ATTRIBUTE_TYPE_INVALID and @value_p to %NULL.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's nametype
- The type of the attributevalue_p
- a pointer to the value (or the pointer itself if the type is a pointer type)flags
- a set of #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the attribute was set, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeByteString
public boolean setAttributeByteString(@Nonnull Str attribute, @Nonnull Str value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.
If @attribute is of a different type, this operation will fail,
returning %FALSE.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a string containing the attribute's new valueflags
- a #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set to @value in the @file, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeByteString
public boolean setAttributeByteString(String attribute, String value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to @value.
If @attribute is of a different type, this operation will fail,
returning %FALSE.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a string containing the attribute's new valueflags
- a #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set to @value in the @file, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeInt32
public boolean setAttributeInt32(@Nonnull Str attribute, int value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.
If @attribute is of a different type, this operation will fail.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a #gint32 containing the attribute's new valueflags
- a #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set to @value in the @file, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeInt32
public boolean setAttributeInt32(String attribute, int value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT32 to @value.
If @attribute is of a different type, this operation will fail.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a #gint32 containing the attribute's new valueflags
- a #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set to @value in the @file, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeInt64
public boolean setAttributeInt64(@Nonnull Str attribute, long value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.
If @attribute is of a different type, this operation will fail.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a #guint64 containing the attribute's new valueflags
- a #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeInt64
public boolean setAttributeInt64(String attribute, long value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_INT64 to @value.
If @attribute is of a different type, this operation will fail.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a #guint64 containing the attribute's new valueflags
- a #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeString
public boolean setAttributeString(@Nonnull Str attribute, @Nonnull Str value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.
If @attribute is of a different type, this operation will fail.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a string containing the attribute's valueflags
- #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeString
public boolean setAttributeString(String attribute, String value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_STRING to @value.
If @attribute is of a different type, this operation will fail.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a string containing the attribute's valueflags
- #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeUint32
public boolean setAttributeUint32(@Nonnull Str attribute, int value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.
If @attribute is of a different type, this operation will fail.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a #guint32 containing the attribute's new valueflags
- a #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set to @value in the @file, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeUint32
public boolean setAttributeUint32(String attribute, int value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT32 to @value.
If @attribute is of a different type, this operation will fail.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a #guint32 containing the attribute's new valueflags
- a #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set to @value in the @file, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeUint64
public boolean setAttributeUint64(@Nonnull Str attribute, long value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.
If @attribute is of a different type, this operation will fail.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a #guint64 containing the attribute's new valueflags
- a #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set to @value in the @file, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributeUint64
public boolean setAttributeUint64(String attribute, long value, int flags, @Nullable Cancellable cancellable) throws AllocationError Sets @attribute of type %G_FILE_ATTRIBUTE_TYPE_UINT64 to @value.
If @attribute is of a different type, this operation will fail.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
attribute
- a string containing the attribute's namevalue
- a #guint64 containing the attribute's new valueflags
- a #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE if the @attribute was successfully set to @value in the @file, %FALSE otherwise.
- Throws:
AllocationError
-
setAttributesAsync
public void setAttributesAsync(@Nonnull FileInfo info, int flags, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously sets the attributes of @file with @info.
For more details, see g_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 g_file_set_attributes_finish() to get
the result of the operation.- Parameters:
info
- a #GFileInfoflags
- a #GFileQueryInfoFlagsio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallbackuser_data
- a #gpointer
-
setAttributesFromInfo
public boolean setAttributesFromInfo(@Nonnull FileInfo info, int flags, @Nullable Cancellable cancellable) throws AllocationError Tries to set all attributes in the #GFileInfo on the target
values, not stopping on the first error.
If there is any error during this operation then @error will
be set to the first error. Error on particular fields are flagged
by setting the "status" field in the attribute value to
%G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can
also detect further errors.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
info
- a #GFileInfoflags
- #GFileQueryInfoFlagscancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %FALSE if there was any error, %TRUE otherwise.
- Throws:
AllocationError
-
setDisplayName
public File setDisplayName(@Nonnull Str display_name, @Nullable Cancellable cancellable) throws AllocationError 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 (%G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the
initial value in the rename widget, and then the result after editing
should be passed to g_file_set_display_name().
On success the resulting converted filename is returned.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
display_name
- a stringcancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFile specifying what @file was renamed to, or %NULL if there was an error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
setDisplayName
public File setDisplayName(String display_name, @Nullable Cancellable cancellable) throws AllocationError 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 (%G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME) should be used as the
initial value in the rename widget, and then the result after editing
should be passed to g_file_set_display_name().
On success the resulting converted filename is returned.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
display_name
- a stringcancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- a #GFile specifying what @file was renamed to, or %NULL if there was an error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
setDisplayNameAsync
public void setDisplayNameAsync(@Nonnull Str display_name, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously sets the display name for a given #GFile.
For more details, see g_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 g_file_set_display_name_finish() to get
the result of the operation.- Parameters:
display_name
- a stringio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
setDisplayNameAsync
public void setDisplayNameAsync(String display_name, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously sets the display name for a given #GFile.
For more details, see g_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 g_file_set_display_name_finish() to get
the result of the operation.- Parameters:
display_name
- a stringio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
setDisplayNameFinish
Finishes setting a display name started with
g_file_set_display_name_async().- Parameters:
res
- a #GAsyncResult- Returns:
- a #GFile or %NULL on error. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
startMountable
public void startMountable(int flags, @Nullable MountOperation start_operation, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Starts a file of type %G_FILE_TYPE_MOUNTABLE.
Using @start_operation, you can request callbacks when, for instance,
passwords are needed during authentication.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
When the operation is finished, @callback will be called.
You can then call g_file_mount_mountable_finish() to get
the result of the operation.- Parameters:
flags
- flags affecting the operationstart_operation
- a #GMountOperation, or %NULL to avoid user interactioncancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfied, or %NULLuser_data
- the data to pass to callback function
-
startMountableFinish
Finishes a start operation. See g_file_start_mountable() for details.
Finish an asynchronous start operation that was started
with g_file_start_mountable().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE if the operation finished successfully. %FALSE otherwise.
- Throws:
AllocationError
-
stopMountable
public void stopMountable(int flags, @Nullable MountOperation mount_operation, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Stops a file of type %G_FILE_TYPE_MOUNTABLE.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
When the operation is finished, @callback will be called.
You can then call g_file_stop_mountable_finish() to get
the result of the operation.- Parameters:
flags
- flags affecting the operationmount_operation
- a #GMountOperation, or %NULL to avoid user interaction.cancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfied, or %NULLuser_data
- the data to pass to callback function
-
stopMountableFinish
Finishes a stop operation, see g_file_stop_mountable() for details.
Finish an asynchronous stop operation that was started
with g_file_stop_mountable().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE if the operation finished successfully. %FALSE otherwise.
- Throws:
AllocationError
-
supportsThreadContexts
public boolean supportsThreadContexts()Checks if @file supports
[thread-default contexts][g-main-context-push-thread-default-context].
If this returns %FALSE, you cannot perform asynchronous operations on
@file in a thread that has a thread-default context.- Returns:
- Whether or not @file supports thread-default contexts.
-
trash
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
%G_IO_ERROR_NOT_SUPPORTED error. Since GLib 2.66, the `x-gvfs-notrash` unix
mount option can be used to disable g_file_trash() support for certain
mounts, the %G_IO_ERROR_NOT_SUPPORTED error will be returned in that case.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE on successful trash, %FALSE otherwise.
- Throws:
AllocationError
-
trashAsync
public void trashAsync(int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously sends @file to the Trash location, if possible.- Parameters:
io_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
trashFinish
Finishes an asynchronous file trashing operation, started with
g_file_trash_async().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE on successful trash, %FALSE otherwise.
- Throws:
AllocationError
-
unmountMountableWithOperation
public void unmountMountableWithOperation(int flags, @Nullable MountOperation mount_operation, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Unmounts a file of type %G_FILE_TYPE_MOUNTABLE.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
When the operation is finished, @callback will be called.
You can then call g_file_unmount_mountable_finish() to get
the result of the operation.- Parameters:
flags
- flags affecting the operationmount_operation
- a #GMountOperation, or %NULL to avoid user interactioncancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is satisfied, or %NULLuser_data
- the data to pass to callback function
-
unmountMountableWithOperationFinish
public boolean unmountMountableWithOperationFinish(@Nonnull AsyncResult result) throws AllocationError Finishes an unmount operation,
see g_file_unmount_mountable_with_operation() for details.
Finish an asynchronous unmount operation that was started
with g_file_unmount_mountable_with_operation().- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE if the operation finished successfully. %FALSE otherwise.
- Throws:
AllocationError
-
newBuildFilename
Constructs a #GFile from a series of elements using the correct
separator for filenames.
Using this function is equivalent to calling g_build_filename(),
followed by g_file_new_for_path() on the result.- Parameters:
first_element
- the first element in the path_elipse
- remaining elements in path, terminated by %NULL- Returns:
- a new #GFile
-
newForCommandlineArg
Creates a #GFile 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. #GApplication also uses UTF-8 but
g_application_command_line_create_file_for_arg() may be more useful
for you there. It is also always possible to use this function with
#GOptionContext arguments of type %G_OPTION_ARG_FILENAME.- Parameters:
arg
- a command line string- Returns:
- a new #GFile. Free the returned object with g_object_unref().
-
newForCommandlineArgAndCwd
Creates a #GFile with the given argument from the command line.
This function is similar to g_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 g_application_command_line_create_file_for_arg().- Parameters:
arg
- a command line stringcwd
- the current working directory of the commandline- Returns:
- a new #GFile
-
newForPath
Constructs a #GFile for a given path. This operation never
fails, but the returned object might not support any I/O
operation if @path is malformed.- Parameters:
path
- a string containing a relative or absolute path. The string must be encoded in the glib filename encoding.- Returns:
- a new #GFile for the given @path. Free the returned object with g_object_unref().
-
newForUri
Constructs a #GFile 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.- Parameters:
uri
- a UTF-8 string containing a URI- Returns:
- a new #GFile for the given @uri. Free the returned object with g_object_unref().
-
newTmpAsync
public static void newTmpAsync(@Nullable Str tmpl, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously opens a file in the preferred directory for temporary files
(as returned by g_get_tmp_dir()) as g_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 %NULL, a default template is used.- Parameters:
tmpl
- Template for the file name, as in g_file_open_tmp(), or %NULL for a default templateio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is doneuser_data
- data to pass to @callback
-
newTmpDirAsync
public static void newTmpDirAsync(@Nullable Str tmpl, int io_priority, @Nullable Cancellable cancellable, File.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously creates a directory in the preferred directory for
temporary files (as returned by g_get_tmp_dir()) as g_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 %NULL, a default template is used.- Parameters:
tmpl
- Template for the file name, as in g_dir_make_tmp(), or %NULL for a default templateio_priority
- the [I/O priority][io-priority] of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- a #GAsyncReadyCallback to call when the request is doneuser_data
- data to pass to @callback
-
newTmpDirFinish
Finishes a temporary directory creation started by
g_file_new_tmp_dir_async().- Parameters:
result
- a #GAsyncResult- Returns:
- a new #GFile. Free the returned object with g_object_unref().
- Throws:
AllocationError
-
parseName
Constructs a #GFile with the given @parse_name (i.e. something
given by g_file_get_parse_name()). This operation never fails,
but the returned object might not support any I/O operation if
the @parse_name cannot be parsed.- Parameters:
parse_name
- a file name or path to be parsed- Returns:
- a new #GFile.
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-