Synopsis#include <gio/gio.h> GFile; GFileIface; enum GFileQueryInfoFlags; enum GFileCreateFlags; enum GFileCopyFlags; enum GFileMonitorFlags; enum GFilesystemPreviewType; void (*GFileProgressCallback) (goffset current_num_bytes, goffset total_num_bytes, gpointer user_data); gboolean (*GFileReadMoreCallback) (const char *file_contents, goffset file_size, gpointer callback_data); GFile* g_file_new_for_path (const char *path); GFile* g_file_new_for_uri (const char *uri); GFile* g_file_new_for_commandline_arg (const char *arg); GFile* g_file_parse_name (const char *parse_name); GFile* g_file_dup (GFile *file); guint g_file_hash (gconstpointer file); gboolean g_file_equal (GFile *file1, GFile *file2); char* g_file_get_basename (GFile *file); char* g_file_get_path (GFile *file); char* g_file_get_uri (GFile *file); char* g_file_get_parse_name (GFile *file); GFile* g_file_get_parent (GFile *file); GFile* g_file_get_child (GFile *file, const char *name); GFile* g_file_get_child_for_display_name (GFile *file, const char *display_name, GError **error); gboolean g_file_has_prefix (GFile *file, GFile *prefix); char* g_file_get_relative_path (GFile *parent, GFile *descendant); GFile* g_file_resolve_relative_path (GFile *file, const char *relative_path); gboolean g_file_is_native (GFile *file); gboolean g_file_has_uri_scheme (GFile *file, const char *uri_scheme); char* g_file_get_uri_scheme (GFile *file); GFileInputStream* g_file_read (GFile *file, GCancellable *cancellable, GError **error); void g_file_read_async (GFile *file, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileInputStream* g_file_read_finish (GFile *file, GAsyncResult *res, GError **error); GFileOutputStream* g_file_append_to (GFile *file, GFileCreateFlags flags, GCancellable *cancellable, GError **error); GFileOutputStream* g_file_create (GFile *file, GFileCreateFlags flags, GCancellable *cancellable, GError **error); GFileOutputStream* g_file_replace (GFile *file, const char *etag, gboolean make_backup, GFileCreateFlags flags, GCancellable *cancellable, GError **error); void g_file_append_to_async (GFile *file, GFileCreateFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileOutputStream* g_file_append_to_finish (GFile *file, GAsyncResult *res, GError **error); void g_file_create_async (GFile *file, GFileCreateFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileOutputStream* g_file_create_finish (GFile *file, GAsyncResult *res, GError **error); void g_file_replace_async (GFile *file, const char *etag, gboolean make_backup, GFileCreateFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileOutputStream* g_file_replace_finish (GFile *file, GAsyncResult *res, GError **error); GFileInfo* g_file_query_info (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); void g_file_query_info_async (GFile *file, const char *attributes, GFileQueryInfoFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileInfo* g_file_query_info_finish (GFile *file, GAsyncResult *res, GError **error); gboolean g_file_query_exists (GFile *file, GCancellable *cancellable); GFileType g_file_query_file_type (GFile *file, GFileQueryInfoFlags flags, GCancellable *cancellable); GFileInfo* g_file_query_filesystem_info (GFile *file, const char *attributes, GCancellable *cancellable, GError **error); void g_file_query_filesystem_info_async (GFile *file, const char *attributes, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileInfo* g_file_query_filesystem_info_finish (GFile *file, GAsyncResult *res, GError **error); GAppInfo* g_file_query_default_handler (GFile *file, GCancellable *cancellable, GError **error); GMount* g_file_find_enclosing_mount (GFile *file, GCancellable *cancellable, GError **error); void g_file_find_enclosing_mount_async (GFile *file, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GMount* g_file_find_enclosing_mount_finish (GFile *file, GAsyncResult *res, GError **error); GFileEnumerator* g_file_enumerate_children (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); void g_file_enumerate_children_async (GFile *file, const char *attributes, GFileQueryInfoFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileEnumerator* g_file_enumerate_children_finish (GFile *file, GAsyncResult *res, GError **error); GFile* g_file_set_display_name (GFile *file, const char *display_name, GCancellable *cancellable, GError **error); void g_file_set_display_name_async (GFile *file, const char *display_name, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFile* g_file_set_display_name_finish (GFile *file, GAsyncResult *res, GError **error); gboolean g_file_delete (GFile *file, GCancellable *cancellable, GError **error); gboolean g_file_trash (GFile *file, GCancellable *cancellable, GError **error); gboolean g_file_copy (GFile *source, GFile *destination, GFileCopyFlags flags, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GError **error); void g_file_copy_async (GFile *source, GFile *destination, GFileCopyFlags flags, int io_priority, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GAsyncReadyCallback callback, gpointer user_data); gboolean g_file_copy_finish (GFile *file, GAsyncResult *res, GError **error); gboolean g_file_move (GFile *source, GFile *destination, GFileCopyFlags flags, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GError **error); gboolean g_file_make_directory (GFile *file, GCancellable *cancellable, GError **error); gboolean g_file_make_directory_with_parents (GFile *file, GCancellable *cancellable, GError **error); gboolean g_file_make_symbolic_link (GFile *file, const char *symlink_value, GCancellable *cancellable, GError **error); GFileAttributeInfoList* g_file_query_settable_attributes (GFile *file, GCancellable *cancellable, GError **error); GFileAttributeInfoList* g_file_query_writable_namespaces (GFile *file, GCancellable *cancellable, GError **error); gboolean g_file_set_attribute (GFile *file, const char *attribute, GFileAttributeType type, gpointer value_p, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); gboolean g_file_set_attributes_from_info (GFile *file, GFileInfo *info, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); void g_file_set_attributes_async (GFile *file, GFileInfo *info, GFileQueryInfoFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean g_file_set_attributes_finish (GFile *file, GAsyncResult *result, GFileInfo **info, GError **error); gboolean g_file_set_attribute_string (GFile *file, const char *attribute, const char *value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); gboolean g_file_set_attribute_byte_string (GFile *file, const char *attribute, const char *value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); gboolean g_file_set_attribute_uint32 (GFile *file, const char *attribute, guint32 value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); gboolean g_file_set_attribute_int32 (GFile *file, const char *attribute, gint32 value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); gboolean g_file_set_attribute_uint64 (GFile *file, const char *attribute, guint64 value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); gboolean g_file_set_attribute_int64 (GFile *file, const char *attribute, gint64 value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); void g_file_mount_mountable (GFile *file, GMountMountFlags flags, GMountOperation *mount_operation, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFile* g_file_mount_mountable_finish (GFile *file, GAsyncResult *result, GError **error); void g_file_unmount_mountable (GFile *file, GMountUnmountFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean g_file_unmount_mountable_finish (GFile *file, GAsyncResult *result, GError **error); void g_file_eject_mountable (GFile *file, GMountUnmountFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean g_file_eject_mountable_finish (GFile *file, GAsyncResult *result, GError **error); void g_file_mount_enclosing_volume (GFile *location, GMountMountFlags flags, GMountOperation *mount_operation, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean g_file_mount_enclosing_volume_finish (GFile *location, GAsyncResult *result, GError **error); GFileMonitor* g_file_monitor_directory (GFile *file, GFileMonitorFlags flags, GCancellable *cancellable, GError **error); GFileMonitor* g_file_monitor_file (GFile *file, GFileMonitorFlags flags, GCancellable *cancellable, GError **error); GFileMonitor* g_file_monitor (GFile *file, GFileMonitorFlags flags, GCancellable *cancellable, GError **error); gboolean g_file_load_contents (GFile *file, GCancellable *cancellable, char **contents, gsize *length, char **etag_out, GError **error); void g_file_load_contents_async (GFile *file, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean g_file_load_contents_finish (GFile *file, GAsyncResult *res, char **contents, gsize *length, char **etag_out, GError **error); void g_file_load_partial_contents_async (GFile *file, GCancellable *cancellable, GFileReadMoreCallback read_more_callback, GAsyncReadyCallback callback, gpointer user_data); gboolean g_file_load_partial_contents_finish (GFile *file, GAsyncResult *res, char **contents, gsize *length, char **etag_out, GError **error); gboolean g_file_replace_contents (GFile *file, const char *contents, gsize length, const char *etag, gboolean make_backup, GFileCreateFlags flags, char **new_etag, GCancellable *cancellable, GError **error); void g_file_replace_contents_async (GFile *file, const char *contents, gsize length, const char *etag, gboolean make_backup, GFileCreateFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean g_file_replace_contents_finish (GFile *file, GAsyncResult *res, char **new_etag, GError **error); gboolean g_file_copy_attributes (GFile *source, GFile *destination, GFileCopyFlags flags, GCancellable *cancellable, GError **error); DescriptionGFile 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:
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
All GFiles have a basename (get with
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
Many GFile operations have both synchronous and asynchronous versions
to suit your application. Asynchronous versions of synchronous functions
simply have
Some GFile operations do not have synchronous analogs, as they may
take a very long time to finish, and blocking may leave an application
unusable. Notable cases include:
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 for HTTP Etag headers, which are a very similar concept.
DetailsGFiletypedef struct _GFile GFile; A handle to an object implementing the GFileIface interface. Generally stores a location within the file system. Handles do not necessarily represent files or directories that currently exist.
GFileIfacetypedef struct { GTypeInterface g_iface; /* Virtual Table */ GFile * (* dup) (GFile *file); guint (* hash) (GFile *file); gboolean (* equal) (GFile *file1, GFile *file2); gboolean (* is_native) (GFile *file); gboolean (* has_uri_scheme) (GFile *file, const char *uri_scheme); char * (* get_uri_scheme) (GFile *file); char * (* get_basename) (GFile *file); char * (* get_path) (GFile *file); char * (* get_uri) (GFile *file); char * (* get_parse_name) (GFile *file); GFile * (* get_parent) (GFile *file); gboolean (* prefix_matches) (GFile *prefix, GFile *file); char * (* get_relative_path) (GFile *parent, GFile *descendant); GFile * (* resolve_relative_path) (GFile *file, const char *relative_path); GFile * (* get_child_for_display_name) (GFile *file, const char *display_name, GError **error); GFileEnumerator * (* enumerate_children) (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); void (* enumerate_children_async) (GFile *file, const char *attributes, GFileQueryInfoFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileEnumerator * (* enumerate_children_finish) (GFile *file, GAsyncResult *res, GError **error); GFileInfo * (* query_info) (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); void (* query_info_async) (GFile *file, const char *attributes, GFileQueryInfoFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileInfo * (* query_info_finish) (GFile *file, GAsyncResult *res, GError **error); GFileInfo * (* query_filesystem_info) (GFile *file, const char *attributes, GCancellable *cancellable, GError **error); void (* query_filesystem_info_async) (GFile *file, const char *attributes, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileInfo * (* query_filesystem_info_finish)(GFile *file, GAsyncResult *res, GError **error); GMount * (* find_enclosing_mount) (GFile *file, GCancellable *cancellable, GError **error); void (* find_enclosing_mount_async) (GFile *file, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GMount * (* find_enclosing_mount_finish) (GFile *file, GAsyncResult *res, GError **error); GFile * (* set_display_name) (GFile *file, const char *display_name, GCancellable *cancellable, GError **error); void (* set_display_name_async) (GFile *file, const char *display_name, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFile * (* set_display_name_finish) (GFile *file, GAsyncResult *res, GError **error); GFileAttributeInfoList * (* query_settable_attributes) (GFile *file, GCancellable *cancellable, GError **error); void (* _query_settable_attributes_async) (void); void (* _query_settable_attributes_finish) (void); GFileAttributeInfoList * (* query_writable_namespaces) (GFile *file, GCancellable *cancellable, GError **error); void (* _query_writable_namespaces_async) (void); void (* _query_writable_namespaces_finish) (void); gboolean (* set_attribute) (GFile *file, const char *attribute, GFileAttributeType type, gpointer value_p, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); gboolean (* set_attributes_from_info) (GFile *file, GFileInfo *info, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); void (* set_attributes_async) (GFile *file, GFileInfo *info, GFileQueryInfoFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean (* set_attributes_finish) (GFile *file, GAsyncResult *result, GFileInfo **info, GError **error); GFileInputStream * (* read_fn) (GFile *file, GCancellable *cancellable, GError **error); void (* read_async) (GFile *file, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileInputStream * (* read_finish) (GFile *file, GAsyncResult *res, GError **error); GFileOutputStream * (* append_to) (GFile *file, GFileCreateFlags flags, GCancellable *cancellable, GError **error); void (* append_to_async) (GFile *file, GFileCreateFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileOutputStream * (* append_to_finish) (GFile *file, GAsyncResult *res, GError **error); GFileOutputStream * (* create) (GFile *file, GFileCreateFlags flags, GCancellable *cancellable, GError **error); void (* create_async) (GFile *file, GFileCreateFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileOutputStream * (* create_finish) (GFile *file, GAsyncResult *res, GError **error); GFileOutputStream * (* replace) (GFile *file, const char *etag, gboolean make_backup, GFileCreateFlags flags, GCancellable *cancellable, GError **error); void (* replace_async) (GFile *file, const char *etag, gboolean make_backup, GFileCreateFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFileOutputStream * (* replace_finish) (GFile *file, GAsyncResult *res, GError **error); gboolean (* delete_file) (GFile *file, GCancellable *cancellable, GError **error); void (* _delete_file_async) (void); void (* _delete_file_finish) (void); gboolean (* trash) (GFile *file, GCancellable *cancellable, GError **error); void (* _trash_async) (void); void (* _trash_finish) (void); gboolean (* make_directory) (GFile *file, GCancellable *cancellable, GError **error); void (* _make_directory_async) (void); void (* _make_directory_finish) (void); gboolean (* make_symbolic_link) (GFile *file, const char *symlink_value, GCancellable *cancellable, GError **error); void (* _make_symbolic_link_async) (void); void (* _make_symbolic_link_finish) (void); gboolean (* copy) (GFile *source, GFile *destination, GFileCopyFlags flags, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GError **error); void (* copy_async) (GFile *source, GFile *destination, GFileCopyFlags flags, int io_priority, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GAsyncReadyCallback callback, gpointer user_data); gboolean (* copy_finish) (GFile *file, GAsyncResult *res, GError **error); gboolean (* move) (GFile *source, GFile *destination, GFileCopyFlags flags, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GError **error); void (* _move_async) (void); void (* _move_finish) (void); void (* mount_mountable) (GFile *file, GMountMountFlags flags, GMountOperation *mount_operation, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); GFile * (* mount_mountable_finish) (GFile *file, GAsyncResult *result, GError **error); void (* unmount_mountable) (GFile *file, GMountUnmountFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean (* unmount_mountable_finish) (GFile *file, GAsyncResult *result, GError **error); void (* eject_mountable) (GFile *file, GMountUnmountFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean (* eject_mountable_finish) (GFile *file, GAsyncResult *result, GError **error); void (* mount_enclosing_volume) (GFile *location, GMountMountFlags flags, GMountOperation *mount_operation, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean (* mount_enclosing_volume_finish) (GFile *location, GAsyncResult *result, GError **error); GFileMonitor * (* monitor_dir) (GFile *file, GFileMonitorFlags flags, GCancellable *cancellable, GError **error); GFileMonitor * (* monitor_file) (GFile *file, GFileMonitorFlags flags, GCancellable *cancellable, GError **error); } GFileIface; An interface for writing VFS file handles.
enum GFileQueryInfoFlagstypedef enum { G_FILE_QUERY_INFO_NONE = 0, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS = (1 << 0) /*< nick=nofollow-symlinks >*/ } GFileQueryInfoFlags; Flags used when querying a GFileInfo.
enum GFileCreateFlagstypedef enum { G_FILE_CREATE_NONE = 0, G_FILE_CREATE_PRIVATE = (1 << 0) } GFileCreateFlags; Flags used when an operation may create a file.
enum GFileCopyFlagstypedef enum { G_FILE_COPY_NONE = 0, /*< nick=none >*/ G_FILE_COPY_OVERWRITE = (1 << 0), G_FILE_COPY_BACKUP = (1 << 1), G_FILE_COPY_NOFOLLOW_SYMLINKS = (1 << 2), G_FILE_COPY_ALL_METADATA = (1 << 3), G_FILE_COPY_NO_FALLBACK_FOR_MOVE = (1 << 4), G_FILE_COPY_TARGET_DEFAULT_PERMS = (1 << 5) } GFileCopyFlags; Flags used when copying or moving files.
enum GFileMonitorFlagstypedef enum { G_FILE_MONITOR_NONE = 0, G_FILE_MONITOR_WATCH_MOUNTS = (1 << 0) } GFileMonitorFlags; Flags used to set what a GFileMonitor will watch for.
enum GFilesystemPreviewTypetypedef enum { G_FILESYSTEM_PREVIEW_TYPE_IF_ALWAYS = 0, G_FILESYSTEM_PREVIEW_TYPE_IF_LOCAL, G_FILESYSTEM_PREVIEW_TYPE_NEVER } GFilesystemPreviewType; Indicates a hint from the file system whether files should be previewed in a file manager. Returned as the value of the key G_FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW.
GFileProgressCallback ()void (*GFileProgressCallback) (goffset current_num_bytes, goffset total_num_bytes, gpointer user_data); When doing file operations that may take a while, such as moving a file or copying a file, a progress callback is used to pass how far along that operation is to the application.
GFileReadMoreCallback ()gboolean (*GFileReadMoreCallback) (const char *file_contents, goffset file_size, gpointer callback_data);
When loading the partial contents of a file with
g_file_new_for_path ()GFile* g_file_new_for_path (const char *path);
Constructs a GFile for a given path. This operation never
fails, but the returned object might not support any I/O
operation if
g_file_new_for_uri ()GFile* g_file_new_for_uri (const char *uri);
Constructs a GFile for a given URI. This operation never
fails, but the returned object might not support any I/O
operation if
g_file_new_for_commandline_arg ()GFile* g_file_new_for_commandline_arg (const char *arg);
Creates a GFile with the given argument from the command line. The value of
g_file_parse_name ()GFile* g_file_parse_name (const char *parse_name);
Constructs a GFile with the given
g_file_dup ()GFile* g_file_dup (GFile *file);
Duplicates a GFile handle. This operation does not duplicate
the actual file or directory represented by the GFile; see
This call does no blocking i/o.
g_file_hash ()guint g_file_hash (gconstpointer file); Creates a hash value for a GFile. This call does no blocking i/o.
g_file_equal ()gboolean g_file_equal (GFile *file1, GFile *file2); Checks equality of two given GFiles. 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.
g_file_get_basename ()char* g_file_get_basename (GFile *file); 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 This call does no blocking i/o.
g_file_get_path ()char* g_file_get_path (GFile *file); Gets the local pathname for GFile, if one exists. This call does no blocking i/o.
g_file_get_uri ()char* g_file_get_uri (GFile *file);
Gets the URI for the This call does no blocking i/o.
g_file_get_parse_name ()char* g_file_get_parse_name (GFile *file);
Gets the parse name of the 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 UTF8 the pathname is used, otherwise the IRI is used (a form of URI that allows UTF8 characters unescaped). This call does no blocking i/o.
g_file_get_parent ()GFile* g_file_get_parent (GFile *file);
Gets the parent directory for the This call does no blocking i/o.
g_file_get_child ()GFile* g_file_get_child (GFile *file, const char *name);
Gets a child of 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.
g_file_get_child_for_display_name ()GFile* g_file_get_child_for_display_name (GFile *file, const char *display_name, GError **error);
Gets the child of This call does no blocking i/o.
g_file_has_prefix ()gboolean g_file_has_prefix (GFile *file, GFile *prefix);
Checks whether
This call does no i/o, as it works purely on names. As such it can
sometimes return
g_file_get_relative_path ()char* g_file_get_relative_path (GFile *parent, GFile *descendant);
Gets the path for This call does no blocking i/o.
g_file_resolve_relative_path ()GFile* g_file_resolve_relative_path (GFile *file, const char *relative_path);
Resolves a relative path for This call does no blocking i/o.
g_file_is_native ()gboolean g_file_is_native (GFile *file); Checks to see if a file is native to the platform. A native file s one expressed in the platform-native filename format, e.g. "C:\Windows" or "/usr/bin/". This does not mean the file is local, as it might be on a locally mounted remote filesystem.
On some systems non-native files may be available using
the native filesystem via a userspace filesystem (FUSE), in
these cases this call will return This call does no blocking i/o.
g_file_has_uri_scheme ()gboolean g_file_has_uri_scheme (GFile *file, const char *uri_scheme); Checks to see if a GFile has a given URI scheme. This call does no blocking i/o.
g_file_get_uri_scheme ()char* g_file_get_uri_scheme (GFile *file); 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. This call does no blocking i/o.
g_file_read ()GFileInputStream* g_file_read (GFile *file, GCancellable *cancellable, GError **error); Opens a file for reading. The result is a GFileInputStream that can be used to read the contents of the file.
If 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.
g_file_read_async ()void g_file_read_async (GFile *file, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Asynchronously opens
For more details, see
When the operation is finished,
g_file_read_finish ()GFileInputStream* g_file_read_finish (GFile *file, GAsyncResult *res, GError **error);
Finishes an asynchronous file read operation started with
g_file_append_to ()GFileOutputStream* g_file_append_to (GFile *file, GFileCreateFlags flags, GCancellable *cancellable, GError **error); 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
If
Some file systems don't allow all file names, and may
return an
g_file_create ()GFileOutputStream* g_file_create (GFile *file, GFileCreateFlags flags, GCancellable *cancellable, GError **error); 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
If 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.
g_file_replace ()GFileOutputStream* g_file_replace (GFile *file, const char *etag, gboolean make_backup, GFileCreateFlags flags, GCancellable *cancellable, GError **error); 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
If
If you pass in a non-NULL
If 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.
g_file_append_to_async ()void g_file_append_to_async (GFile *file, GFileCreateFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Asynchronously opens
For more details, see
When the operation is finished,
g_file_append_to_finish ()GFileOutputStream* g_file_append_to_finish (GFile *file, GAsyncResult *res, GError **error);
Finishes an asynchronous file append operation started with
g_file_create_async ()void g_file_create_async (GFile *file, GFileCreateFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer 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
When the operation is finished,
g_file_create_finish ()GFileOutputStream* g_file_create_finish (GFile *file, GAsyncResult *res, GError **error);
Finishes an asynchronous file create operation started with
g_file_replace_async ()void g_file_replace_async (GFile *file, const char *etag, gboolean make_backup, GFileCreateFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); Asynchronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first.
For more details, see
When the operation is finished,
g_file_replace_finish ()GFileOutputStream* g_file_replace_finish (GFile *file, GAsyncResult *res, GError **error);
Finishes an asynchronous file replace operation started with
g_file_query_info ()GFileInfo* g_file_query_info (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error);
Gets the requested information about specified
The
If
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 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.
g_file_query_info_async ()void g_file_query_info_async (GFile *file, const char *attributes, GFileQueryInfoFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Asynchronously gets the requested information about specified
For more details, see
When the operation is finished,
g_file_query_info_finish ()GFileInfo* g_file_query_info_finish (GFile *file, GAsyncResult *res, GError **error);
Finishes an asynchronous file info query.
See
g_file_query_exists ()gboolean g_file_query_exists (GFile *file, GCancellable *cancellable);
Utility function to check if a particular file exists. This is
implemented using Note that in many cases it is racy to first check for file existence and then execute something based on the outcome of that, because the file might have been created or removed in between the operations. The general approach to handling that is to not check, but just do the operation and handle the errors as they come.
As an example of race-free checking, take the case of reading a file, and
if it doesn't exist, creating it. There are two racy versions: read it, and
on error create it; and: check if it exists, if not create it. These
can both result in two processes creating the file (with perhaps a partially
written file as the result). The correct approach is to always try to create
the file with However, in many cases an existence check is useful in a user interface, for instance to make a menu item sensitive/insensitive, so that you don't have to fool users that something is possible and then just show and error dialog. If you do this, you should make sure to also handle the errors that can happen due to races when you execute the operation.
g_file_query_file_type ()GFileType g_file_query_file_type (GFile *file, GFileQueryInfoFlags flags, GCancellable *cancellable);
Utility function to inspect the GFileType of a file. This is
implemented using The primary use case of this method is to check if a file is a regular file, directory, or symlink.
Since 2.18 g_file_query_filesystem_info ()GFileInfo* g_file_query_filesystem_info (GFile *file, const char *attributes, GCancellable *cancellable, GError **error);
Similar to
The
If 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.
g_file_query_filesystem_info_async ()void g_file_query_filesystem_info_async (GFile *file, const char *attributes, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Asynchronously gets the requested information about the filesystem
that the specified
For more details, see
When the operation is finished,
g_file_query_filesystem_info_finish ()GFileInfo* g_file_query_filesystem_info_finish (GFile *file, GAsyncResult *res, GError **error);
Finishes an asynchronous filesystem info query. See
g_file_query_default_handler ()GAppInfo* g_file_query_default_handler (GFile *file, GCancellable *cancellable, GError **error);
Returns the GAppInfo that is registered as the default
application to handle the file specified by
If
g_file_find_enclosing_mount ()GMount* g_file_find_enclosing_mount (GFile *file, GCancellable *cancellable, GError **error);
If the GFileIface for
If
g_file_find_enclosing_mount_async ()void g_file_find_enclosing_mount_async (GFile *file, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); Asynchronously gets the mount for the file.
For more details, see
When the operation is finished,
g_file_find_enclosing_mount_finish ()GMount* g_file_find_enclosing_mount_finish (GFile *file, GAsyncResult *res, GError **error);
Finishes an asynchronous find mount request.
See
g_file_enumerate_children ()GFileEnumerator* g_file_enumerate_children (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); 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
If 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_FILE_ERROR_NOTDIR error will be returned. Other errors are possible too.
g_file_enumerate_children_async ()void g_file_enumerate_children_async (GFile *file, const char *attributes, GFileQueryInfoFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer 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
When the operation is finished,
g_file_enumerate_children_finish ()GFileEnumerator* g_file_enumerate_children_finish (GFile *file, GAsyncResult *res, GError **error);
Finishes an async enumerate children operation.
See
g_file_set_display_name ()GFile* g_file_set_display_name (GFile *file, const char *display_name, GCancellable *cancellable, GError **error);
Renames
The display name is converted from UTF8 to the correct encoding for the target
filesystem if possible and the
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 On success the resulting converted filename is returned.
If
g_file_set_display_name_async ()void g_file_set_display_name_async (GFile *file, const char *display_name, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); Asynchronously sets the display name for a given GFile.
For more details, see
When the operation is finished,
g_file_set_display_name_finish ()GFile* g_file_set_display_name_finish (GFile *file, GAsyncResult *res, GError **error);
Finishes setting a display name started with
g_file_delete ()gboolean g_file_delete (GFile *file, GCancellable *cancellable, GError **error);
Deletes a file. If the
If
g_file_trash ()gboolean g_file_trash (GFile *file, GCancellable *cancellable, GError **error);
Sends
If
g_file_copy ()gboolean g_file_copy (GFile *source, GFile *destination, GFileCopyFlags flags, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GError **error);
Copies the file
If the flag G_FILE_COPY_OVERWRITE is specified an already
existing
If the flag G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
will be copied as symlinks, otherwise the target of the
If
If
If the If G_FILE_COPY_OVERWRITE is not specified and the target exists, then the error G_IO_ERROR_EXISTS is returned. If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY error is returned. If trying to overwrite a directory with a directory the G_IO_ERROR_WOULD_MERGE error is returned. If the source is a directory and the target does not exist, or G_FILE_COPY_OVERWRITE is specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error is returned.
If you are interested in copying the GFile object itself (not the on-disk
file), see
g_file_copy_async ()void g_file_copy_async (GFile *source, GFile *destination, GFileCopyFlags flags, int io_priority, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GAsyncReadyCallback callback, gpointer user_data);
Copies the file
If
When the operation is finished,
g_file_copy_finish ()gboolean g_file_copy_finish (GFile *file, GAsyncResult *res, GError **error);
Finishes copying the file started with
g_file_move ()gboolean g_file_move (GFile *source, GFile *destination, GFileCopyFlags flags, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GError **error);
Tries to move the file or directory
If the flag G_FILE_COPY_OVERWRITE is specified an already
existing
If the flag G_FILE_COPY_NOFOLLOW_SYMLINKS is specified then symlinks
will be copied as symlinks, otherwise the target of the
If
If
If the If G_FILE_COPY_OVERWRITE is not specified and the target exists, then the error G_IO_ERROR_EXISTS is returned. If trying to overwrite a file over a directory the G_IO_ERROR_IS_DIRECTORY error is returned. If trying to overwrite a directory with a directory the G_IO_ERROR_WOULD_MERGE error is returned. If the source is a directory and the target does not exist, or G_FILE_COPY_OVERWRITE is specified and the target is a file, then the G_IO_ERROR_WOULD_RECURSE error may be returned (if the native move operation isn't available).
g_file_make_directory ()gboolean g_file_make_directory (GFile *file, GCancellable *cancellable, GError **error);
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 For a local GFile the newly created directory will have the default (current) ownership and permissions of the current process.
If
g_file_make_directory_with_parents ()gboolean g_file_make_directory_with_parents (GFile *file, GCancellable *cancellable, GError **error);
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 For a local GFile the newly created directories will have the default (current) ownership and permissions of the current process.
If
Since 2.18 g_file_make_symbolic_link ()gboolean g_file_make_symbolic_link (GFile *file, const char *symlink_value, GCancellable *cancellable, GError **error); Creates a symbolic link.
If
g_file_query_settable_attributes ()GFileAttributeInfoList* g_file_query_settable_attributes (GFile *file, GCancellable *cancellable, GError **error); 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
g_file_query_writable_namespaces ()GFileAttributeInfoList* g_file_query_writable_namespaces (GFile *file, GCancellable *cancellable, GError **error); 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
g_file_set_attribute ()gboolean g_file_set_attribute (GFile *file, const char *attribute, GFileAttributeType type, gpointer value_p, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error);
Sets an attribute in the file with attribute name
If
g_file_set_attributes_from_info ()gboolean g_file_set_attributes_from_info (GFile *file, GFileInfo *info, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error); 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
If
g_file_set_attributes_async ()void g_file_set_attributes_async (GFile *file, GFileInfo *info, GFileQueryInfoFlags flags, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Asynchronously sets the attributes of
For more details, see
When the operation is finished,
g_file_set_attributes_finish ()gboolean g_file_set_attributes_finish (GFile *file, GAsyncResult *result, GFileInfo **info, GError **error);
Finishes setting an attribute started in
g_file_set_attribute_string ()gboolean g_file_set_attribute_string (GFile *file, const char *attribute, const char *value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error);
Sets
If
g_file_set_attribute_byte_string ()gboolean g_file_set_attribute_byte_string (GFile *file, const char *attribute, const char *value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error);
Sets
If
g_file_set_attribute_uint32 ()gboolean g_file_set_attribute_uint32 (GFile *file, const char *attribute, guint32 value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error);
Sets
If
g_file_set_attribute_int32 ()gboolean g_file_set_attribute_int32 (GFile *file, const char *attribute, gint32 value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error);
Sets
If
g_file_set_attribute_uint64 ()gboolean g_file_set_attribute_uint64 (GFile *file, const char *attribute, guint64 value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error);
Sets
If
g_file_set_attribute_int64 ()gboolean g_file_set_attribute_int64 (GFile *file, const char *attribute, gint64 value, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error);
Sets
If
g_file_mount_mountable ()void g_file_mount_mountable (GFile *file, GMountMountFlags flags, GMountOperation *mount_operation, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Mounts a file of type G_FILE_TYPE_MOUNTABLE.
Using
If
When the operation is finished,
g_file_mount_mountable_finish ()GFile* g_file_mount_mountable_finish (GFile *file, GAsyncResult *result, GError **error);
Finishes a mount operation. See
Finish an asynchronous mount operation that was started
with
g_file_unmount_mountable ()void g_file_unmount_mountable (GFile *file, GMountUnmountFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
If
When the operation is finished,
g_file_unmount_mountable_finish ()gboolean g_file_unmount_mountable_finish (GFile *file, GAsyncResult *result, GError **error);
Finishes an unmount operation, see
Finish an asynchronous unmount operation that was started
with
g_file_eject_mountable ()void g_file_eject_mountable (GFile *file, GMountUnmountFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Starts an asynchronous eject on a mountable.
When this operation has completed,
If
g_file_eject_mountable_finish ()gboolean g_file_eject_mountable_finish (GFile *file, GAsyncResult *result, GError **error);
Finishes an asynchronous eject operation started by
g_file_mount_enclosing_volume ()void g_file_mount_enclosing_volume (GFile *location, GMountMountFlags flags, GMountOperation *mount_operation, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Starts a
When this operation has completed,
If
g_file_mount_enclosing_volume_finish ()gboolean g_file_mount_enclosing_volume_finish (GFile *location, GAsyncResult *result, GError **error);
Finishes a mount operation started by
g_file_monitor_directory ()GFileMonitor* g_file_monitor_directory (GFile *file, GFileMonitorFlags flags, GCancellable *cancellable, GError **error); Obtains a directory monitor for the given file. This may fail if directory monitoring is not supported.
If
g_file_monitor_file ()GFileMonitor* g_file_monitor_file (GFile *file, GFileMonitorFlags flags, GCancellable *cancellable, GError **error); Obtains a file monitor for the given file. If no file notification mechanism exists, then regular polling of the file is used.
If
g_file_monitor ()GFileMonitor* g_file_monitor (GFile *file, GFileMonitorFlags flags, GCancellable *cancellable, GError **error); Obtains a file or directory monitor for the given file, depending on the type of the file.
If
Since 2.18 g_file_load_contents ()gboolean g_file_load_contents (GFile *file, GCancellable *cancellable, char **contents, gsize *length, char **etag_out, GError **error);
Loads the content of the file into memory. The data is always
zero-terminated, but this is not included in the resultant
If
g_file_load_contents_async ()void g_file_load_contents_async (GFile *file, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Starts an asynchronous load of the
For more details, see
When the load operation has completed,
If
g_file_load_contents_finish ()gboolean g_file_load_contents_finish (GFile *file, GAsyncResult *res, char **contents, gsize *length, char **etag_out, GError **error);
Finishes an asynchronous load of the
g_file_load_partial_contents_async ()void g_file_load_partial_contents_async (GFile *file, GCancellable *cancellable, GFileReadMoreCallback read_more_callback, GAsyncReadyCallback callback, gpointer user_data);
Reads the partial contents of a file. A GFileReadMoreCallback should be
used to stop reading from the file when appropriate, else this function
will behave exactly as
Users of this function should be aware that
If
g_file_load_partial_contents_finish ()gboolean g_file_load_partial_contents_finish (GFile *file, GAsyncResult *res, char **contents, gsize *length, char **etag_out, GError **error);
Finishes an asynchronous partial load operation that was started
with
g_file_replace_contents ()gboolean g_file_replace_contents (GFile *file, const char *contents, gsize length, const char *etag, gboolean make_backup, GFileCreateFlags flags, char **new_etag, GCancellable *cancellable, GError **error);
Replaces the contents of
If
If
The returned
g_file_replace_contents_async ()void g_file_replace_contents_async (GFile *file, const char *contents, gsize length, const char *etag, gboolean make_backup, GFileCreateFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
Starts an asynchronous replacement of
When this operation has completed,
If
If
g_file_replace_contents_finish ()gboolean g_file_replace_contents_finish (GFile *file, GAsyncResult *res, char **new_etag, GError **error);
Finishes an asynchronous replace of the given
g_file_copy_attributes ()gboolean g_file_copy_attributes (GFile *source, GFile *destination, GFileCopyFlags flags, GCancellable *cancellable, GError **error);
Copies the file attributes from
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. mtime). However
if G_FILE_COPY_ALL_METADATA is specified in
|