glibmm: Gio::File Class Reference

File and directory handling. More...

#include <giomm/file.h>

Inheritance diagram for Gio::File:

Public Types

using SlotFileProgress = sigc::slot< void(goffset, goffset)>
 A signal handler would be, for instance: void on_file_progress(goffset current_num_bytes, goffset total_num_bytes);. More...

 
using SlotFileMeasureProgress = sigc::slot< void(bool, guint64, guint64, guint64)>
 This slot type is used by measure_disk_usage() to make periodic progress reports when measuring the amount of disk spaced used by a directory. More...

 
using SlotReadMore = sigc::slot< bool(const char*, goffset)>
 A signal handler would be, for instance: bool on_read_more(const char* file_contents, goffset file_size);. More...

 
- Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify func_destroy_notify
 
- Public Types inherited from sigc::notifiable
typedef internal::func_destroy_notify func_destroy_notify
 

Public Member Functions

 File (File&& src) noexcept
 
Fileoperator= (File&& src) noexcept
 
 ~File () noexcept override
 
GFile* gobj ()
 Provides access to the underlying C GObject. More...

 
const GFile* gobj () const
 Provides access to the underlying C GObject. More...

 
Glib::RefPtr< Filedup () const
 Duplicates a File handle. More...

 
guint hash () const
 Creates a hash value for a File. More...

 
bool equal (const Glib::RefPtr< const File >& other) const
 Checks equality of two given Files. More...

 
std::string get_basename () const
 Gets the base name (the last component of the path) for a given File. More...

 
std::string get_path () const
 Gets the local pathname for File, if one exists. More...

 
std::string get_uri () const
 Gets the URI for the file. More...

 
Glib::ustring get_parse_name () const
 Gets the parse name of the file. More...

 
Glib::RefPtr< Fileget_parent () const
 Gets the parent directory for the file. More...

 
bool has_parent (const Glib::RefPtr< File >& parent) const
 Checks if file has a parent, and optionally, if it is parent. More...

 
bool has_parent () const
 Checks if the file has any parent at all. More...

 
Glib::RefPtr< Fileget_child (const std::string& name) const
 Gets a child of file with basename equal to name. More...

 
Glib::RefPtr< Fileget_child_for_display_name (const Glib::ustring& display_name) const
 Gets the child of file for a given display_name (i.e. a UTF-8 version of the name). More...

 
bool has_prefix (const Glib::RefPtr< const File >& prefix) const
 Checks whether file has the prefix specified by prefix. More...

 
std::string get_relative_path (const Glib::RefPtr< const File >& descendant) const
 Gets the path for descendant relative to parent. More...

 
Glib::RefPtr< Fileresolve_relative_path (const std::string& relative_path) const
 Resolves a relative path for file to an absolute path. More...

 
bool is_native () const
 Checks to see if a file is native to the platform. More...

 
bool has_uri_scheme (const std::string& uri_scheme) const
 Checks to see if a File has a given URI scheme. More...

 
std::string get_uri_scheme () const
 Gets the URI scheme for a File. More...

 
Glib::RefPtr< FileInputStreamread (const Glib::RefPtr< Cancellable >& cancellable)
 Opens a file for reading. More...

 
Glib::RefPtr< FileInputStreamread ()
 A read() convenience overload. More...

 
void read_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously opens the file for reading. More...

 
void read_async (const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously opens the file for reading. More...

 
Glib::RefPtr< FileInputStreamread_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an asynchronous file read operation started with g_file_read_async(). More...

 
Glib::RefPtr< FileOutputStreamappend_to (const Glib::RefPtr< Cancellable >& cancellable, CreateFlags flags=CreateFlags::NONE)
 Gets an output stream for appending data to the file. More...

 
Glib::RefPtr< FileOutputStreamappend_to (CreateFlags flags=CreateFlags::NONE)
 Gets an output stream for appending data to the file. More...

 
Glib::RefPtr< FileOutputStreamcreate_file (const Glib::RefPtr< Cancellable >& cancellable, CreateFlags flags=CreateFlags::NONE)
 Creates a new file and returns an output stream for writing to it. More...

 
Glib::RefPtr< FileOutputStreamcreate_file (CreateFlags flags=CreateFlags::NONE)
 Creates a new file and returns an output stream for writing to it. More...

 
Glib::RefPtr< FileIOStreamcreate_file_readwrite (const Glib::RefPtr< Cancellable >& cancellable, CreateFlags flags=CreateFlags::NONE)
 Creates a new file and returns a stream for reading and writing to it. More...

 
Glib::RefPtr< FileIOStreamcreate_file_readwrite (CreateFlags flags=CreateFlags::NONE)
 Creates a new file and returns a stream for reading and writing to it. More...

 
Glib::RefPtr< FileOutputStreamreplace (const Glib::RefPtr< Cancellable >& cancellable, const std::string& etag={}, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Returns an output stream for overwriting the file, possibly creating a backup copy of the file first. More...

 
Glib::RefPtr< FileOutputStreamreplace (const std::string& etag={}, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Returns an output stream for overwriting the file, possibly creating a backup copy of the file first. More...

 
void append_to_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, CreateFlags flags=CreateFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously opens the file for appending. More...

 
void append_to_async (const SlotAsyncReady& slot, CreateFlags flags=CreateFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously opens the file for appending. More...

 
Glib::RefPtr< FileOutputStreamappend_to_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an asynchronous file append operation started with g_file_append_to_async(). More...

 
void create_file_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, CreateFlags flags=CreateFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously creates a new file and returns an output stream for writing to it. More...

 
void create_file_async (const SlotAsyncReady& slot, CreateFlags flags=CreateFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously creates a new file and returns an output stream for writing to it. More...

 
Glib::RefPtr< FileOutputStreamcreate_file_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an asynchronous file create operation started with g_file_create_async(). More...

 
void create_file_readwrite_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, CreateFlags flags=CreateFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously creates a new file and returns a stream for reading and writing to it. More...

 
void create_file_readwrite_async (const SlotAsyncReady& slot, CreateFlags flags=CreateFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously creates a new file and returns a stream for reading and writing to it. More...

 
Glib::RefPtr< FileIOStreamcreate_file_readwrite_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an asynchronous file create operation started with g_file_create_readwrite_async(). More...

 
void replace_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const std::string& etag={}, bool make_backup=false, CreateFlags flags=CreateFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asyncronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first. More...

 
void replace_async (const SlotAsyncReady& slot, const std::string& etag={}, bool make_backup=false, CreateFlags flags=CreateFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asyncronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first. More...

 
Glib::RefPtr< FileOutputStreamreplace_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an asynchronous file replace operation started with g_file_replace_async(). More...

 
Glib::RefPtr< FileIOStreamopen_readwrite (const Glib::RefPtr< Cancellable >& cancellable)
 Opens an existing file for reading and writing. More...

 
Glib::RefPtr< FileIOStreamopen_readwrite ()
 A open_readwrite() convenience overload. More...

 
void open_readwrite_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Opens an existing file for reading and writing. More...

 
void open_readwrite_async (const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Opens an existing file for reading and writing. More...

 
Glib::RefPtr< FileIOStreamopen_readwrite_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an asynchronous file read operation started with g_file_open_readwrite_async(). More...

 
Glib::RefPtr< FileIOStreamreplace_readwrite (const Glib::RefPtr< Cancellable >& cancellable, const std::string& etag={}, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Returns an output stream for overwriting the file in readwrite mode, possibly creating a backup copy of the file first. More...

 
Glib::RefPtr< FileIOStreamreplace_readwrite (const std::string& etag={}, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Returns an output stream for overwriting the file in readwrite mode, possibly creating a backup copy of the file first. More...

 
void replace_readwrite_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const std::string& etag={}, bool make_backup=false, CreateFlags flags=CreateFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asyncronously overwrites the file in read-write mode, replacing the contents, possibly creating a backup copy of the file first. More...

 
void replace_readwrite_async (const SlotAsyncReady& slot, const std::string& etag={}, bool make_backup=false, CreateFlags flags=CreateFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asyncronously overwrites the file in read-write mode, replacing the contents, possibly creating a backup copy of the file first. More...

 
Glib::RefPtr< FileIOStreamreplace_readwrite_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an asynchronous file replace operation started with g_file_replace_readwrite_async(). More...

 
Glib::RefPtr< FileInfoquery_info (const Glib::RefPtr< Cancellable >& cancellable, const std::string& attributes="*", FileQueryInfoFlags flags=FileQueryInfoFlags::NONE) const
 Gets the requested information about the file. More...

 
Glib::RefPtr< FileInfoquery_info (const std::string& attributes="*", FileQueryInfoFlags flags=FileQueryInfoFlags::NONE) const
 Gets the requested information about the file. More...

 
bool query_exists (const Glib::RefPtr< Cancellable >& cancellable) const
 Utility function to check if a particular file exists. More...

 
bool query_exists () const
 A query_exists() convenience overload. More...

 
FileType query_file_type (FileQueryInfoFlags flags, const Glib::RefPtr< Cancellable >& cancellable) const
 Utility function to inspect the FileType of a file. More...

 
FileType query_file_type (FileQueryInfoFlags flags=FileQueryInfoFlags::NONE) const
 Utility function to inspect the FileType of a file. More...

 
void query_info_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const std::string& attributes="*", FileQueryInfoFlags flags=FileQueryInfoFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT) const
 Asynchronously gets the requested information about specified file. More...

 
void query_info_async (const SlotAsyncReady& slot, const std::string& attributes="*", FileQueryInfoFlags flags=FileQueryInfoFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT) const
 Asynchronously gets the requested information about specified file. More...

 
Glib::RefPtr< FileInfoquery_info_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an asynchronous file info query. More...

 
Glib::RefPtr< FileInfoquery_filesystem_info (const Glib::RefPtr< Cancellable >& cancellable, const std::string& attributes="*")
 Similar to query_info(), but obtains information about the filesystem the file is on, rather than the file itself. More...

 
Glib::RefPtr< FileInfoquery_filesystem_info (const std::string& attributes="*")
 Similar to query_info(), but obtains information about the filesystem the file is on, rather than the file itself. More...

 
Glib::RefPtr< Mountfind_enclosing_mount (const Glib::RefPtr< Cancellable >& cancellable)
 Gets a Mount for the File. More...

 
Glib::RefPtr< Mountfind_enclosing_mount ()
 A find_enclosing_mount() convenience overload. More...

 
void query_filesystem_info_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const std::string& attributes="*", int io_priority=Glib::PRIORITY_DEFAULT) const
 Asynchronously gets the requested information about the filesystem that the file is on. More...

 
void query_filesystem_info_async (const SlotAsyncReady& slot, const std::string& attributes="*", int io_priority=Glib::PRIORITY_DEFAULT) const
 Asynchronously gets the requested information about the filesystem that the file is on. More...

 
Glib::RefPtr< FileInfoquery_filesystem_info_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an asynchronous filesystem info query. More...

 
void find_enclosing_mount_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously gets the mount for the file. More...

 
void find_enclosing_mount_async (const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously gets the mount for the file. More...

 
Glib::RefPtr< Mountfind_enclosing_mount_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an asynchronous find mount request. More...

 
Glib::RefPtr< FileEnumeratorenumerate_children (const Glib::RefPtr< Cancellable >& cancellable, const std::string& attributes="*", FileQueryInfoFlags flags=FileQueryInfoFlags::NONE)
 Gets the requested information about the files in a directory. More...

 
Glib::RefPtr< FileEnumeratorenumerate_children (const std::string& attributes="*", FileQueryInfoFlags flags=FileQueryInfoFlags::NONE)
 Gets the requested information about the files in a directory. More...

 
void enumerate_children_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const std::string& attributes="*", FileQueryInfoFlags flags=FileQueryInfoFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously gets the requested information about the files in a directory. More...

 
void enumerate_children_async (const SlotAsyncReady& slot, const std::string& attributes="*", FileQueryInfoFlags flags=FileQueryInfoFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously gets the requested information about the files in a directory. More...

 
Glib::RefPtr< FileEnumeratorenumerate_children_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes an async enumerate children operation. More...

 
Glib::RefPtr< Fileset_display_name (const Glib::ustring& display_name, const Glib::RefPtr< Cancellable >& cancellable)
 Renames file to the specified display name. More...

 
Glib::RefPtr< Fileset_display_name (const Glib::ustring& display_name)
 A set_display_name() convenience overload. More...

 
void set_display_name_async (const Glib::ustring& display_name, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously sets the display name for a given Gio::File. More...

 
void set_display_name_async (const Glib::ustring& display_name, const SlotAsyncReady& slot, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously sets the display name for a given Gio::File. More...

 
Glib::RefPtr< Fileset_display_name_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes setting a display name started with g_file_set_display_name_async(). More...

 
bool remove (const Glib::RefPtr< Cancellable >& cancellable)
 Deletes a file. More...

 
bool remove ()
 A remove() convenience overload. More...

 
void remove_async (const SlotAsyncReady& slot_ready, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously delete a file. More...

 
void remove_async (const SlotAsyncReady& slot_ready, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously delete a file. More...

 
bool remove_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes deleting a file started with g_file_delete_async(). More...

 
bool trash (const Glib::RefPtr< Cancellable >& cancellable)
 Sends file to the "Trashcan", if possible. More...

 
bool trash ()
 A trash() convenience overload. More...

 
void trash_async (const SlotAsyncReady& slot_ready, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously sends the file to the Trash location, if possible. More...

 
void trash_async (const SlotAsyncReady& slot_ready, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously sends the file to the Trash location, if possible. More...

 
bool trash_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes an asynchronous file trashing operation, started with g_file_trash_async(). More...

 
bool copy (const Glib::RefPtr< File >& destination, const SlotFileProgress& slot, const Glib::RefPtr< Cancellable >& cancellable, CopyFlags flags=CopyFlags::NONE)
 Copies the file source to the location specified by destination. More...

 
bool copy (const Glib::RefPtr< File >& destination, const SlotFileProgress& slot, CopyFlags flags=CopyFlags::NONE)
 Copies the file source to the location specified by destination. More...

 
bool copy (const Glib::RefPtr< File >& destination, CopyFlags flags=CopyFlags::NONE)
 Copies the file source to the location specified by destination. More...

 
void copy_async (const Glib::RefPtr< File >& destination, const SlotFileProgress& slot_progress, const SlotAsyncReady& slot_ready, const Glib::RefPtr< Cancellable >& cancellable, CopyFlags flags=CopyFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Copies the file to the location specified by destination asynchronously. More...

 
void copy_async (const Glib::RefPtr< File >& destination, const SlotAsyncReady& slot_ready, const Glib::RefPtr< Cancellable >& cancellable, CopyFlags flags=CopyFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Copies the file to the location specified by destination asynchronously. More...

 
void copy_async (const Glib::RefPtr< File >& destination, const SlotFileProgress& slot_progress, const SlotAsyncReady& slot_ready, CopyFlags flags=CopyFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Copies the file to the location specified by destination asynchronously. More...

 
void copy_async (const Glib::RefPtr< File >& destination, const SlotAsyncReady& slot_ready, CopyFlags flags=CopyFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Copies the file to the location specified by destination asynchronously. More...

 
bool copy_finish (const Glib::RefPtr< AsyncResult >& res)
 Finishes copying the file started with g_file_copy_async(). More...

 
bool move (const Glib::RefPtr< File >& destination, const SlotFileProgress& slot, const Glib::RefPtr< Cancellable >& cancellable, CopyFlags flags=CopyFlags::NONE)
 Tries to move the file or directory source to the location specified by destination. More...

 
bool move (const Glib::RefPtr< File >& destination, const SlotFileProgress& slot, CopyFlags flags=CopyFlags::NONE)
 
bool move (const Glib::RefPtr< File >& destination, CopyFlags flags=CopyFlags::NONE)
 
bool make_directory (const Glib::RefPtr< Cancellable >& cancellable)
 Creates a directory. More...

 
bool make_directory ()
 A make_directory() convenience overload. More...

 
void make_directory_async (const SlotAsyncReady& slot_ready, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously creates a directory. More...

 
void make_directory_async (const SlotAsyncReady& slot_ready, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously creates a directory. More...

 
bool make_directory_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes an asynchronous directory creation, started with g_file_make_directory_async(). More...

 
bool make_directory_with_parents (const Glib::RefPtr< Cancellable >& cancellable)
 Creates a directory and any parent directories that may not exist similar to 'mkdir -p'. More...

 
bool make_directory_with_parents ()
 A make_directory_with_parents() convenience overload. More...

 
bool make_symbolic_link (const std::string& symlink_value, const Glib::RefPtr< Cancellable >& cancellable)
 Creates a symbolic link. More...

 
bool make_symbolic_link (const std::string& symlink_value)
 A make_symbolic_link() convenience overload. More...

 
Glib::RefPtr< FileAttributeInfoListquery_settable_attributes (const Glib::RefPtr< Cancellable >& cancellable)
 Obtain the list of settable attributes for the file. More...

 
Glib::RefPtr< FileAttributeInfoListquery_settable_attributes ()
 A query_settable_attributes() convenience overload. More...

 
Glib::RefPtr< FileAttributeInfoListquery_writable_namespaces (const Glib::RefPtr< Cancellable >& cancellable)
 Obtain the list of attribute namespaces where new attributes can be created by a user. More...

 
Glib::RefPtr< FileAttributeInfoListquery_writable_namespaces ()
 A query_writable_namespaces() convenience overload. More...

 
bool set_attributes_from_info (const Glib::RefPtr< FileInfo >& info, const Glib::RefPtr< Cancellable >& cancellable, FileQueryInfoFlags flags=FileQueryInfoFlags::NONE)
 Tries to set all attributes in the FileInfo on the target values, not stopping on the first error. More...

 
bool set_attributes_from_info (const Glib::RefPtr< FileInfo >& info, FileQueryInfoFlags flags=FileQueryInfoFlags::NONE)
 Tries to set all attributes in the FileInfo on the target values, not stopping on the first error. More...

 
void set_attributes_async (const Glib::RefPtr< FileInfo >& info, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, FileQueryInfoFlags flags=FileQueryInfoFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously sets the attributes of file with info. More...

 
void set_attributes_async (const Glib::RefPtr< FileInfo >& info, const SlotAsyncReady& slot, FileQueryInfoFlags flags=FileQueryInfoFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Asynchronously sets the attributes of file with info. More...

 
bool set_attributes_finish (const Glib::RefPtr< AsyncResult >& result, const Glib::RefPtr< FileInfo >& info)
 
bool set_attribute_string (const std::string& attribute, const Glib::ustring& value, FileQueryInfoFlags flags, const Glib::RefPtr< Cancellable >& cancellable)
 Sets attribute of type G_FILE_ATTRIBUTE_TYPE_STRING to value. More...

 
bool set_attribute_string (const std::string& attribute, const Glib::ustring& value, FileQueryInfoFlags flags)
 A set_attribute_string() convenience overload. More...

 
bool set_attribute_byte_string (const std::string& attribute, const std::string& value, FileQueryInfoFlags flags, const Glib::RefPtr< Cancellable >& cancellable)
 Sets attribute of type G_FILE_ATTRIBUTE_TYPE_BYTE_STRING to value. More...

 
bool set_attribute_byte_string (const std::string& attribute, const std::string& value, FileQueryInfoFlags flags)
 A set_attribute_byte_string() convenience overload. More...

 
bool set_attribute_uint32 (const std::string& attribute, guint32 value, FileQueryInfoFlags flags, const Glib::RefPtr< Cancellable >& cancellable)
 Sets attribute of type G_FILE_ATTRIBUTE_TYPE_UINT32 to value. More...

 
bool set_attribute_uint32 (const std::string& attribute, guint32 value, FileQueryInfoFlags flags)
 A set_attribute_uint32() convenience overload. More...

 
bool set_attribute_int32 (const std::string& attribute, gint32 value, FileQueryInfoFlags flags, const Glib::RefPtr< Cancellable >& cancellable)
 Sets attribute of type G_FILE_ATTRIBUTE_TYPE_INT32 to value. More...

 
bool set_attribute_int32 (const std::string& attribute, gint32 value, FileQueryInfoFlags flags)
 A set_attribute_int32() convenience overload. More...

 
bool set_attribute_uint64 (const std::string& attribute, guint64 value, FileQueryInfoFlags flags, const Glib::RefPtr< Cancellable >& cancellable)
 Sets attribute of type G_FILE_ATTRIBUTE_TYPE_UINT64 to value. More...

 
bool set_attribute_uint64 (const std::string& attribute, guint64 value, FileQueryInfoFlags flags)
 A set_attribute_uint64() convenience overload. More...

 
bool set_attribute_int64 (const std::string& attribute, gint64 value, FileQueryInfoFlags flags, const Glib::RefPtr< Cancellable >& cancellable)
 Sets attribute of type G_FILE_ATTRIBUTE_TYPE_INT64 to value. More...

 
bool set_attribute_int64 (const std::string& attribute, gint64 value, FileQueryInfoFlags flags)
 A set_attribute_int64() convenience overload. More...

 
void mount_enclosing_volume (const Glib::RefPtr< MountOperation >& mount_operation, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, Mount::MountFlags flags=Mount::MountFlags::NONE)
 Starts a mount_operation, mounting the volume that contains the file. More...

 
void mount_enclosing_volume (const Glib::RefPtr< MountOperation >& mount_operation, const SlotAsyncReady& slot, Mount::MountFlags flags=Mount::MountFlags::NONE)
 Starts a mount_operation, mounting the volume that contains the file. More...

 
void mount_enclosing_volume (const SlotAsyncReady& slot, Mount::MountFlags flags=Mount::MountFlags::NONE)
 Starts a mount_operation, mounting the volume that contains the file. More...

 
void mount_enclosing_volume (Mount::MountFlags flags=Mount::MountFlags::NONE)
 Starts a mount_operation, mounting the volume that contains the file. More...

 
bool mount_enclosing_volume_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes a mount operation started by g_file_mount_enclosing_volume(). More...

 
void mount_mountable (const Glib::RefPtr< MountOperation >& mount_operation, const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, Mount::MountFlags flags=Mount::MountFlags::NONE)
 Mounts a file of type FILE_TYPE_MOUNTABLE. More...

 
void mount_mountable (const Glib::RefPtr< MountOperation >& mount_operation, const SlotAsyncReady& slot, Mount::MountFlags flags=Mount::MountFlags::NONE)
 Mounts a file of type FILE_TYPE_MOUNTABLE. More...

 
void mount_mountable (const SlotAsyncReady& slot, Mount::MountFlags flags=Mount::MountFlags::NONE)
 Mounts a file of type FILE_TYPE_MOUNTABLE without user interaction. More...

 
void mount_mountable (Mount::MountFlags flags=Mount::MountFlags::NONE)
 Mounts a file of type FILE_TYPE_MOUNTABLE without user interaction. More...

 
Glib::RefPtr< Filemount_mountable_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes a mount operation. More...

 
void unmount_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Unmounts a file of type FILE_TYPE_MOUNTABLE. More...

 
void unmount_mountable (const SlotAsyncReady& slot, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Unmounts a file of type FILE_TYPE_MOUNTABLE. More...

 
void unmount_mountable (Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Unmounts a file of type FILE_TYPE_MOUNTABLE. More...

 
void unmount_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const Glib::RefPtr< MountOperation >& mount_operation, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Unmounts a file of type FILE_TYPE_MOUNTABLE. More...

 
void unmount_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< MountOperation >& mount_operation, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Unmounts a file of type FILE_TYPE_MOUNTABLE. More...

 
void unmount_mountable (const Glib::RefPtr< MountOperation >& mount_operation, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Unmounts a file of type FILE_TYPE_MOUNTABLE. More...

 
bool unmount_mountable_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes an unmount operation, see g_file_unmount_mountable_with_operation() for details. More...

 
void eject_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Starts an asynchronous eject on a mountable. More...

 
void eject_mountable (const SlotAsyncReady& slot, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Starts an asynchronous eject on a mountable. More...

 
void eject_mountable (Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Starts an asynchronous eject on a mountable. More...

 
void eject_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const Glib::RefPtr< MountOperation >& mount_operation, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Starts an asynchronous eject on a mountable. More...

 
void eject_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< MountOperation >& mount_operation, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Starts an asynchronous eject on a mountable. More...

 
void eject_mountable (const Glib::RefPtr< MountOperation >& mount_operation, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Starts an asynchronous eject on a mountable. More...

 
bool eject_mountable_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes an asynchronous eject operation started by g_file_eject_mountable_with_operation(). More...

 
bool copy_attributes (const Glib::RefPtr< File >& destination, const Glib::RefPtr< Cancellable >& cancellable, CopyFlags flags=CopyFlags::NONE)
 Copies the file attributes from source to destination. More...

 
bool copy_attributes (const Glib::RefPtr< File >& destination, CopyFlags flags=CopyFlags::NONE)
 Copies the file attributes from source to destination. More...

 
Glib::RefPtr< FileMonitormonitor_directory (const Glib::RefPtr< Cancellable >& cancellable, FileMonitorFlags flags=FileMonitorFlags::NONE)
 Obtains a directory monitor for the given file. More...

 
Glib::RefPtr< FileMonitormonitor_directory (FileMonitorFlags flags=FileMonitorFlags::NONE)
 Obtains a directory monitor for the given file. More...

 
Glib::RefPtr< FileMonitormonitor_file (const Glib::RefPtr< Cancellable >& cancellable, FileMonitorFlags flags=FileMonitorFlags::NONE)
 Obtains a file monitor for the given file. More...

 
Glib::RefPtr< FileMonitormonitor_file (FileMonitorFlags flags=FileMonitorFlags::NONE)
 Obtains a file monitor for the given file. More...

 
Glib::RefPtr< FileMonitormonitor (const Glib::RefPtr< Cancellable >& cancellable, FileMonitorFlags flags=FileMonitorFlags::NONE)
 Obtains a file monitor for the given file. More...

 
Glib::RefPtr< FileMonitormonitor (FileMonitorFlags flags=FileMonitorFlags::NONE)
 Obtains a file monitor for the given file. More...

 
void measure_disk_usage (const Glib::RefPtr< Cancellable >& cancellable, const SlotFileMeasureProgress& slot_progress, guint64& disk_usage, guint64& num_dirs, guint64& num_files, MeasureFlags flags=MeasureFlags::NONE)
 Recursively measures the disk usage of the file. More...

 
void measure_disk_usage_async (const SlotAsyncReady& slot_ready, const Glib::RefPtr< Cancellable >& cancellable, const SlotFileMeasureProgress& slot_progress, MeasureFlags flags=MeasureFlags::NONE, int io_priority=Glib::PRIORITY_DEFAULT)
 Recursively measures the disk usage of the file. More...

 
bool measure_disk_usage_finish (const Glib::RefPtr< AsyncResult >& result, guint64& disk_usage, guint64& num_dirs, guint64& num_files)
 Collects the results from an earlier call to g_file_measure_disk_usage_async(). More...

 
void start_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const Glib::RefPtr< MountOperation >& start_operation, Drive::StartFlags flags=Drive::StartFlags::NONE)
 Starts a file of type Mountable. More...

 
void start_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< MountOperation >& start_operation, Drive::StartFlags flags=Drive::StartFlags::NONE)
 Starts a file of type Mountable. More...

 
bool start_mountable_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes a start operation. More...

 
void stop_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const Glib::RefPtr< MountOperation >& start_operation, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Stops a file of type Mountable. More...

 
void stop_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< MountOperation >& start_operation, Mount::UnmountFlags flags=Mount::UnmountFlags::NONE)
 Stops a file of type Mountable. More...

 
bool stop_mountable_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes a stop operation, see g_file_stop_mountable() for details. More...

 
void poll_mountable (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable)
 Polls a file of type Mountable. More...

 
void poll_mountable (const SlotAsyncReady& slot)
 Polls a file of type Mountable. More...

 
bool poll_mountable_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes a poll operation. More...

 
Glib::RefPtr< AppInfoquery_default_handler (const Glib::RefPtr< Cancellable >& cancellable)
 Returns the AppInfo that is registered as the default application to handle the file specified by file. More...

 
Glib::RefPtr< AppInfoquery_default_handler ()
 A query_default_handler() convenience overload. More...

 
bool load_contents (const Glib::RefPtr< Cancellable >& cancellable, char*& contents, gsize& length, std::string& etag_out)
 Loads the content of the file into memory, returning the size of the data. More...

 
bool load_contents (const Glib::RefPtr< Cancellable >& cancellable, char*& contents, gsize& length)
 Loads the content of the file into memory, returning the size of the data. More...

 
bool load_contents (char*& contents, gsize& length, std::string& etag_out)
 Loads the content of the file into memory, returning the size of the data. More...

 
bool load_contents (char*& contents, gsize& length)
 Loads the content of the file into memory, returning the size of the data. More...

 
void load_contents_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable)
 Starts an asynchronous load of the file's contents. More...

 
void load_contents_async (const SlotAsyncReady& slot)
 Starts an asynchronous load of the file's contents. More...

 
bool load_contents_finish (const Glib::RefPtr< AsyncResult >& result, char*& contents, gsize& length, std::string& etag_out)
 Finishes an asynchronous load of the file's contents. More...

 
bool load_contents_finish (const Glib::RefPtr< AsyncResult >& result, char*& contents, gsize& length)
 Finishes an asynchronous load of the file's contents. More...

 
void load_partial_contents_async (const SlotReadMore& slot_read_more, const SlotAsyncReady& slot_async_ready, const Glib::RefPtr< Cancellable >& cancellable)
 Reads the partial contents of a file. More...

 
void load_partial_contents_async (const SlotReadMore& slot_read_more, const SlotAsyncReady& slot_async_ready)
 Reads the partial contents of a file. More...

 
bool load_partial_contents_finish (const Glib::RefPtr< AsyncResult >& result, char*& contents, gsize& length, std::string& etag_out)
 Finishes an asynchronous partial load operation that was started with load_partial_contents_async(). More...

 
bool load_partial_contents_finish (const Glib::RefPtr< AsyncResult >& result, char*& contents, gsize& length)
 Finishes an asynchronous partial load operation that was started with load_partial_contents_async(). More...

 
void replace_contents (const char* contents, gsize length, const std::string& etag, std::string& new_etag, const Glib::RefPtr< Cancellable >& cancellable, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Replaces the contents of the file with contents of length bytes. More...

 
void replace_contents (const char* contents, gsize length, const std::string& etag, std::string& new_etag, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Replaces the contents of the file with contents of length bytes. More...

 
void replace_contents (const std::string& contents, const std::string& etag, std::string& new_etag, const Glib::RefPtr< Cancellable >& cancellable, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Replaces the contents of the file with contents. More...

 
void replace_contents (const std::string& contents, const std::string& etag, std::string& new_etag, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Replaces the contents of the file with contents. More...

 
void replace_contents_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const char* contents, gsize length, const std::string& etag, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Starts an asynchronous replacement of the file with the given contents of length bytes. More...

 
void replace_contents_async (const SlotAsyncReady& slot, const char* contents, gsize length, const std::string& etag, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Starts an asynchronous replacement of the file with the given contents of length bytes. More...

 
void replace_contents_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const std::string& contents, const std::string& etag, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Starts an asynchronous replacement of the file with the given contents of length bytes. More...

 
void replace_contents_async (const SlotAsyncReady& slot, const std::string& contents, const std::string& etag, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Starts an asynchronous replacement of the file with the given contents. More...

 
void replace_contents_finish (const Glib::RefPtr< AsyncResult >& result, std::string& new_etag)
 Finishes an asynchronous replace of the given file . More...

 
void replace_contents_finish (const Glib::RefPtr< AsyncResult >& result)
 Finishes an asynchronous replace of the given file . More...

 
void replace_contents_bytes_async (const SlotAsyncReady& slot, const Glib::RefPtr< Cancellable >& cancellable, const Glib::RefPtr< const Glib::Bytes >& contents, const std::string& etag, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Same as replace_contents_async() but takes a Gio::Bytes input instead. More...

 
void replace_contents_bytes_async (const SlotAsyncReady& slot, const Glib::RefPtr< const Glib::Bytes >& contents, const std::string& etag, bool make_backup=false, CreateFlags flags=CreateFlags::NONE)
 Same as replace_contents_async() but takes a Gio::Bytes input instead. More...

 
bool supports_thread_contexts () const
 Checks if file supports [thread-default contexts][g-main-context-push-thread-default-context]. More...

 
- Public Member Functions inherited from Glib::Interface
 Interface ()
 A Default constructor. More...

 
 Interface (Interface&& src) noexcept
 
Interfaceoperator= (Interface&& src) noexcept
 
 Interface (const Glib::Interface_Class& interface_class)
 Called by constructors of derived classes. More...

 
 Interface (GObject* castitem)
 Called by constructors of derived classes. More...

 
 ~Interface () noexcept override
 
 Interface (const Interface&)=delete
 
Interfaceoperator= (const Interface&)=delete
 
GObject* gobj ()
 
const GObject* gobj () const
 
- Public Member Functions inherited from Glib::ObjectBase
 ObjectBase (const ObjectBase&)=delete
 
ObjectBaseoperator= (const ObjectBase&)=delete
 
void set_property_value (const Glib::ustring& property_name, const Glib::ValueBase& value)
 You probably want to use a specific property_*() accessor method instead. More...

 
void get_property_value (const Glib::ustring& property_name, Glib::ValueBase& value) const
 You probably want to use a specific property_*() accessor method instead. More...

 
template<class PropertyType >
void set_property (const Glib::ustring& property_name, const PropertyType& value)
 You probably want to use a specific property_*() accessor method instead. More...

 
template<class PropertyType >
void get_property (const Glib::ustring& property_name, PropertyType& value) const
 You probably want to use a specific property_*() accessor method instead. More...

 
template<class PropertyType >
PropertyType get_property (const Glib::ustring& property_name) const
 You probably want to use a specific property_*() accessor method instead. More...

 
sigc::connection connect_property_changed (const Glib::ustring& property_name, const sigc::slot< void()>& slot)
 You can use the signal_changed() signal of the property proxy instead. More...

 
sigc::connection connect_property_changed (const Glib::ustring& property_name, sigc::slot< void()>&& slot)
 You can use the signal_changed() signal of the property proxy instead. More...

 
void freeze_notify ()
 Increases the freeze count on object. More...

 
void thaw_notify ()
 Reverts the effect of a previous call to freeze_notify(). More...

 
virtual void reference () const
 Increment the reference count for this object. More...

 
virtual void unreference () const
 Decrement the reference count for this object. More...

 
GObject* gobj ()
 Provides access to the underlying C GObject. More...

 
const GObject* gobj () const
 Provides access to the underlying C GObject. More...

 
GObject* gobj_copy () const
 Give a ref-ed copy to someone. Use for direct struct access. More...

 
- Public Member Functions inherited from sigc::trackable
 trackable () noexcept
 
 trackable (const trackable &src) noexcept
 
 trackable (trackable &&src) noexcept
 
 ~trackable ()
 
void add_destroy_notify_callback (notifiable *data, func_destroy_notify func) const
 
void notify_callbacks ()
 
trackableoperator= (const trackable &src)
 
trackableoperator= (trackable &&src) noexcept
 
void remove_destroy_notify_callback (notifiable *data) const
 

Static Public Member Functions

static void add_interface (GType gtype_implementer)
 
static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...

 
static Glib::RefPtr< Filecreate_for_path (const std::string& path)
 Constructs a File for a given path. More...

 
static Glib::RefPtr< Filecreate_for_uri (const std::string& uri)
 Constructs a File for a given URI. More...

 
static Glib::RefPtr< Filecreate_for_commandline_arg (const std::string&arg)
 Constructs a File for a given argument from the command line. More...

 
static Glib::RefPtr< Filecreate_for_parse_name (const Glib::ustring& parse_name)
 

Protected Member Functions

 File ()
 You should derive from this class to use it. More...

 
- Protected Member Functions inherited from Glib::ObjectBase
 ObjectBase ()
 This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...

 
 ObjectBase (const char* custom_type_name)
 A derived constructor always overrides this choice. More...

 
 ObjectBase (const std::type_info& custom_type_info)
 This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...

 
 ObjectBase (ObjectBase&& src) noexcept
 
ObjectBaseoperator= (ObjectBase&& src) noexcept
 
virtual ~ObjectBase () noexcept=0
 
void initialize (GObject* castitem)
 
void initialize_move (GObject* castitem, Glib::ObjectBase* previous_wrapper)
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gio::Filewrap (GFile* object, bool take_copy=false)
 A Glib::wrap() method for this object. More...

 

Detailed Description

File and directory handling.

Gio::File is a high level abstraction for manipulating files on a virtual file system. Gio::Files are lightweight, immutable objects that do no I/O upon creation. It is necessary to understand that a Gio::File object does not represent a file, merely a handle to a file. All file I/O is implemented as streaming operations (see Gio::InputStream and Gio::OutputStream).

A GioFile can be constructed from a path, URI, or a command line argument.

You can move through the filesystem with Gio::File handles with get_parent() to get a handle to the parent directory, get_child() to get a handle to a child within a directory, and resolve_relative_path() to resolve a relative path between two Gio::Files.

Many Gio::File operations have both synchronous and asynchronous versions to suit your application. Asynchronous versions of synchronous functions simply have _async() appended to their function names. The asynchronous I/O functions call a SlotAsyncReady callback slot which is then used to finalize the operation, producing a AsyncResult which is then passed to the function's matching _finish() operation.

Some Gio::File operations do not have synchronous analogs, as they may take a very long time to finish, and blocking may leave an application unusable. Notable cases include: mount_mountable() to mount a mountable file, unmount_mountable() to unmount a mountable file, and eject_mountable() to eject a mountable file.

One notable feature of Gio::Files are entity tags, or "etags" for short. Entity tags are somewhat like a more abstract version of the traditional mtime, and can be used to quickly determine if the file has been modified from the version on the file system. See the HTTP 1.1 specification for HTTP Etag headers, which are a very similar concept.

Since glibmm 2.16:

Member Typedef Documentation

using Gio::File::SlotFileMeasureProgress = sigc::slot<void(bool, guint64, guint64, guint64)>

This slot type is used by measure_disk_usage() to make periodic progress reports when measuring the amount of disk spaced used by a directory.

These calls are made on a best-effort basis and not all types of GFile will support them. At the minimum, however, one call will always be made immediately.

In the case that there is no support, reporting will be set to false (and the other values undefined) and no further calls will be made. Otherwise, the reporting will be true and the other values all-zeros during the first (immediate) call. In this way, you can know which type of progress UI to show without a delay.

For measure_disk_usage() the callback is made directly. For measure_disk_usage_async() the callback is made via the default main context of the calling thread (ie: the same way that the final async result would be reported).

current_size is in the same units as requested by the operation (see FILE_DISK_USAGE_APPARENT_SIZE).

The frequency of the updates is implementation defined, but is ideally about once every 200ms.

The last progress callback may or may not be equal to the final result. Always check the async result to get the final value.

For instance, void on_file_measure_progress(bool reporting, guint64 current_size, guint64 num_dirs, guint64 num_files);

Parameters
reportingtrue if more reports will come.
current_sizeThe current cumulative size measurement.
num_dirsThe number of directories visited so far.
num_filesThe number of non-directory files encountered.
Since glibmm 2.38:
using Gio::File::SlotFileProgress = sigc::slot<void(goffset, goffset)>

A signal handler would be, for instance: void on_file_progress(goffset current_num_bytes, goffset total_num_bytes);.

using Gio::File::SlotReadMore = sigc::slot<bool(const char*, goffset)>

A signal handler would be, for instance: bool on_read_more(const char* file_contents, goffset file_size);.

Constructor & Destructor Documentation

Gio::File::File ( )
protected

You should derive from this class to use it.

Gio::File::File ( File&&  src)
noexcept
Gio::File::~File ( )
overridenoexcept

Member Function Documentation

static void Gio::File::add_interface ( GType  gtype_implementer)
static
Glib::RefPtr<FileOutputStream> Gio::File::append_to ( const Glib::RefPtr< Cancellable >&  cancellable,
CreateFlags  flags = CreateFlags::NONE 
)

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 CreateFlags::PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Some filesystems don't allow all filenames, and may throw a Gio::Error with INVALID_FILENAME. If the file is a directory a Gio::Error with IS_DIRECTORY will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
flagsA set of CreateFlags.
cancellableOptional Cancellable object.
Returns
A FileOutputStream.
Glib::RefPtr<FileOutputStream> Gio::File::append_to ( CreateFlags  flags = CreateFlags::NONE)

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 CreateFlags::PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

Some filesystems don't allow all filenames, and may throw a Gio::Error with INVALID_FILENAME. If the file is a directory a Gio::Error with IS_DIRECTORY will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
flagsA set of CreateFlags.
Returns
A FileOutputStream.
void Gio::File::append_to_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
CreateFlags  flags = CreateFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously opens the file for appending.

For more details, see append_to() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call append_to_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
flagsa set of CreateFlags.
io_priorityThe I/O priority of the request.
void Gio::File::append_to_async ( const SlotAsyncReady &  slot,
CreateFlags  flags = CreateFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously opens the file for appending.

For more details, see append_to() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call append_to_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
flagsa set of CreateFlags.
io_priorityThe I/O priority of the request.
Glib::RefPtr<FileOutputStream> Gio::File::append_to_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an asynchronous file append operation started with g_file_append_to_async().

Parameters
resAsyncResult.
Returns
A valid FileOutputStream or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
bool Gio::File::copy ( const Glib::RefPtr< File >&  destination,
const SlotFileProgress slot,
const Glib::RefPtr< Cancellable >&  cancellable,
CopyFlags  flags = CopyFlags::NONE 
)

Copies the file source to the location specified by destination.

Can not handle recursive copies of directories. If the flag CopyFlags::OVERWRITE is specified an already existing destination file is overwritten. If the flag CopyFlags::NOFOLLOW_SYMLINKS is specified then symlinks will be copied as symlinks, otherwise the target of the source symlink will be copied.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

The operation can be monitored via the slot callback.

If the source file does not exist then a Gio::Error with NOT_FOUND will be thrown, independent on the status of the destination.

If CopyFlags::OVERWRITE is not specified and the target exists, then a Gio::Error with EXISTS will be thrown.

If trying to overwrite a file over a directory a Gio::Error with IS_DIRECTORY will be thrown. If trying to overwrite a directory with a directory a Gio::Error with WOULD_MERGE will be thrown.

If the source is a directory and the target does not exist, or CopyFlags::OVERWRITE is specified and the target is a file, then a Gio::Error with WOULD_RECURSE will be thrown.

If you are interested in copying the Gio::File object itself (not the on-disk file), see File::dup().

bool Gio::File::copy ( const Glib::RefPtr< File >&  destination,
const SlotFileProgress slot,
CopyFlags  flags = CopyFlags::NONE 
)

Copies the file source to the location specified by destination.

Can not handle recursive copies of directories. If the flag CopyFlags::OVERWRITE is specified an already existing destination file is overwritten. If the flag CopyFlags::NOFOLLOW_SYMLINKS is specified then symlinks will be copied as symlinks, otherwise the target of the source symlink will be copied.

The operation can be monitored via the slot callback.

If the source file does not exist then a Gio::Error with NOT_FOUND will be thrown, independent on the status of the destination.

If CopyFlags::OVERWRITE is not specified and the target exists, then a Gio::Error with EXISTS will be thrown.

If trying to overwrite a file over a directory a Gio::Error with IS_DIRECTORY will be thrown. If trying to overwrite a directory with a directory a Gio::Error with WOULD_MERGE will be thrown.

If the source is a directory and the target does not exist, or CopyFlags::OVERWRITE is specified and the target is a file, then a Gio::Error with WOULD_RECURSE will be thrown.

If you are interested in copying the Gio::File object itself (not the on-disk file), see File::dup().

bool Gio::File::copy ( const Glib::RefPtr< File >&  destination,
CopyFlags  flags = CopyFlags::NONE 
)

Copies the file source to the location specified by destination.

Can not handle recursive copies of directories. If the flag CopyFlags::OVERWRITE is specified an already existing destination file is overwritten. If the flag CopyFlags::NOFOLLOW_SYMLINKS is specified then symlinks will be copied as symlinks, otherwise the target of the source symlink will be copied.

If the source file does not exist then a Gio::Error with NOT_FOUND will be thrown, independent on the status of the destination.

If CopyFlags::OVERWRITE is not specified and the target exists, then a Gio::Error with EXISTS will be thrown.

If trying to overwrite a file over a directory a Gio::Error with IS_DIRECTORY will be thrown. If trying to overwrite a directory with a directory a Gio::Error with WOULD_MERGE will be thrown.

If the source is a directory and the target does not exist, or CopyFlags::OVERWRITE is specified and the target is a file, then a Gio::Error with WOULD_RECURSE will be thrown.

If you are interested in copying the Gio::File object itself (not the on-disk file), see File::dup().

void Gio::File::copy_async ( const Glib::RefPtr< File >&  destination,
const SlotFileProgress slot_progress,
const SlotAsyncReady &  slot_ready,
const Glib::RefPtr< Cancellable >&  cancellable,
CopyFlags  flags = CopyFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Copies the file to the location specified by destination asynchronously.

For details of the behaviour, see copy().

When the operation is finished, slot_ready will be called. You can then call copy_finish() to get the result of the operation.

The function specified by slot_progress will be called just like in copy(), however the callback will run in the main loop, not in the thread that is doing the I/O operation.

Parameters
destinationDestination File
slot_progressThe callback slot to be called with progress information
slot_readyA SlotAsyncReady to call when the request is satisfied
cancellableA Cancellable object which can be used to cancel the operation
flagsSet of CopyFlags
io_priorityThe I/O priority of the request
void Gio::File::copy_async ( const Glib::RefPtr< File >&  destination,
const SlotAsyncReady &  slot_ready,
const Glib::RefPtr< Cancellable >&  cancellable,
CopyFlags  flags = CopyFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Copies the file to the location specified by destination asynchronously.

For details of the behaviour, see copy().

When the operation is finished, slot_ready will be called. You can then call copy_finish() to get the result of the operation.

Parameters
destinationDestination File
slot_readyA SlotAsyncReady to call when the request is satisfied
cancellableA Cancellable object which can be used to cancel the operation
flagsSet of CopyFlags
io_priorityThe I/O priority of the request
void Gio::File::copy_async ( const Glib::RefPtr< File >&  destination,
const SlotFileProgress slot_progress,
const SlotAsyncReady &  slot_ready,
CopyFlags  flags = CopyFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Copies the file to the location specified by destination asynchronously.

For details of the behaviour, see copy().

When the operation is finished, slot_ready will be called. You can then call copy_finish() to get the result of the operation.

The function specified by slot_progress will be called just like in copy(), however the callback will run in the main loop, not in the thread that is doing the I/O operation.

Parameters
destinationDestination File
slot_progressThe callback slot to be called with progress information
slot_readyA SlotAsyncReady to call when the request is satisfied
flagsSet of CopyFlags
io_priorityThe I/O priority of the request
void Gio::File::copy_async ( const Glib::RefPtr< File >&  destination,
const SlotAsyncReady &  slot_ready,
CopyFlags  flags = CopyFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Copies the file to the location specified by destination asynchronously.

For details of the behaviour, see copy().

When the operation is finished, slot_ready will be called. You can then call copy_finish() to get the result of the operation.

Parameters
destinationDestination File
slot_readyA SlotAsyncReady to call when the request is satisfied
flagsSet of CopyFlags
io_priorityThe I/O priority of the request
bool Gio::File::copy_attributes ( const Glib::RefPtr< File >&  destination,
const Glib::RefPtr< Cancellable >&  cancellable,
CopyFlags  flags = CopyFlags::NONE 
)

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. mtime). However if CopyFlags::ALL_METADATA is specified in flags, then all the metadata that is possible to copy is copied.

Parameters
destinationA File to copy attributes to.
cancellableA Cancellable object.
flagsA set of FileMonitorFlags.
Returns
true if the attributes were copied successfully, false otherwise.
bool Gio::File::copy_attributes ( const Glib::RefPtr< File >&  destination,
CopyFlags  flags = CopyFlags::NONE 
)

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. mtime). However if CopyFlags::ALL_METADATA is specified in flags, then all the metadata that is possible to copy is copied.

Parameters
destinationA File to copy attributes to.
flagsA set of FileMonitorFlags.
Returns
true if the attributes were copied successfully, false otherwise.
bool Gio::File::copy_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes copying the file started with g_file_copy_async().

Parameters
resA AsyncResult.
Returns
A true on success, false on error.
Exceptions
Glib::Error
Glib::RefPtr<FileOutputStream> Gio::File::create_file ( const Glib::RefPtr< Cancellable >&  cancellable,
CreateFlags  flags = CreateFlags::NONE 
)

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 CreateFlags::PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

If a file with this name already exists a Gio::Error with EXISTS will be thrown. If the file is a directory a Gio::Error with IS_DIRECTORY will be thrown.

Some filesystems don't allow all filenames, and may throw a Gio::Error with INVALID_FILENAME, and if the name is to longa Gio::Error with FILENAME_TOO_LONG will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
cancellableA Cancellable object which can be used to cancel the operation.
flagsa set of CreateFlags.
Returns
A FileOutputStream for the newly created file.
Glib::RefPtr<FileOutputStream> Gio::File::create_file ( CreateFlags  flags = CreateFlags::NONE)

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 CreateFlags::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 a file with this name already exists a Gio::Error with EXISTS will be thrown. If the file is a directory a Gio::Error with IS_DIRECTORY will be thrown.

Some filesystems don't allow all filenames, and may throw a Gio::Error with INVALID_FILENAME, and if the name is to longa Gio::Error with FILENAME_TOO_LONG will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
flagsa set of CreateFlags.
Returns
A FileOutputStream for the newly created file.
void Gio::File::create_file_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
CreateFlags  flags = CreateFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously creates a new file and returns an output stream for writing to it.

The file must not already exist. For more details, see create_file() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call create_file_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
flagsa set of CreateFlags.
io_priorityThe I/O priority of the request.
void Gio::File::create_file_async ( const SlotAsyncReady &  slot,
CreateFlags  flags = CreateFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously creates a new file and returns an output stream for writing to it.

The file must not already exist. For more details, see create_file() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call create_file_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
flagsa set of CreateFlags.
io_priorityThe I/O priority of the request.
Glib::RefPtr<FileOutputStream> Gio::File::create_file_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an asynchronous file create operation started with g_file_create_async().

Parameters
resA AsyncResult.
Returns
A FileOutputStream or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
Glib::RefPtr<FileIOStream> Gio::File::create_file_readwrite ( const Glib::RefPtr< Cancellable >&  cancellable,
CreateFlags  flags = CreateFlags::NONE 
)

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 CreateFlags::PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

If a file with this name already exists a Gio::Error with EXISTS will be thrown. If the file is a directory a Gio::Error with IS_DIRECTORY will be thrown.

Some filesystems don't allow all filenames, and may throw a Gio::Error with INVALID_FILENAME, and if the name is to longa Gio::Error with FILENAME_TOO_LONG will be thrown. 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
cancellableA Cancellable object which can be used to cancel the operation.
flagsa set of CreateFlags.
Returns
A FileOutputStream for the newly created file.
Glib::RefPtr<FileIOStream> Gio::File::create_file_readwrite ( CreateFlags  flags = CreateFlags::NONE)

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 CreateFlags::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 a file with this name already exists a Gio::Error with EXISTS will be thrown. If the file is a directory a Gio::Error with IS_DIRECTORY will be thrown.

Some filesystems don't allow all filenames, and may throw a Gio::Error with INVALID_FILENAME, and if the name is to longa Gio::Error with FILENAME_TOO_LONG will be thrown. 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
flagsa set of CreateFlags.
Returns
A FileOutputStream for the newly created file.
void Gio::File::create_file_readwrite_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
CreateFlags  flags = CreateFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

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 create_file_readwrite() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call create_file_readwrite_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
flagsa set of CreateFlags.
io_priorityThe I/O priority of the request.
Since glibmm 2.24:
void Gio::File::create_file_readwrite_async ( const SlotAsyncReady &  slot,
CreateFlags  flags = CreateFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

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 create_file_readwrite() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call create_file_readwrite_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
flagsa set of CreateFlags.
io_priorityThe I/O priority of the request.
Since glibmm 2.24:
Glib::RefPtr<FileIOStream> Gio::File::create_file_readwrite_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an asynchronous file create operation started with g_file_create_readwrite_async().

Since glibmm 2.22:
Parameters
resA AsyncResult.
Returns
A FileIOStream or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
static Glib::RefPtr<File> Gio::File::create_for_commandline_arg ( const std::string arg)
static

Constructs a File for a 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.

Parameters
argA string containing a relative or absolute path.
Returns
A new instantiation of an appropriate Gio::File class.
static Glib::RefPtr<File> Gio::File::create_for_parse_name ( const Glib::ustring parse_name)
static
static Glib::RefPtr<File> Gio::File::create_for_path ( const std::string path)
static

Constructs a File for a given path.

This operation never fails, but the returned object might not support any I/O operation if path is malformed.

Parameters
pathA string containing a relative or absolute path.
Returns
A new instantiation of an appropriate Gio::File class.
static Glib::RefPtr<File> Gio::File::create_for_uri ( const std::string uri)
static

Constructs a File for a given URI.

This operation never fails, but the returned object might not support any I/O operation if path is malformed.

Parameters
uriA string containing a URI.
Returns
A new instantiation of an appropriate Gio::File class.
Glib::RefPtr<File> Gio::File::dup ( ) const

Duplicates a File handle.

This operation does not duplicate the actual file or directory represented by the File; 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 (File is not thread-safe). For use within the same thread, use Glib::object_ref() to increment the existing object’s reference count.

This call does no blocking I/O.

Returns
A new File that is a duplicate of the given File.
void Gio::File::eject_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Starts an asynchronous eject on a mountable.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

When the operation is finished, slot will be called. You can then call eject_mountable_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
flagsFlags affecting the operation.
void Gio::File::eject_mountable ( const SlotAsyncReady &  slot,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Starts an asynchronous eject on a mountable.

When the operation is finished, slot will be called. You can then call eject_mountable_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
flagsFlags affecting the operation.
void Gio::File::eject_mountable ( Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE)

Starts an asynchronous eject on a mountable.

Parameters
flagsFlags affecting the operation.
void Gio::File::eject_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const Glib::RefPtr< MountOperation >&  mount_operation,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Starts an asynchronous eject on a mountable.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

When the operation is finished, slot will be called. You can then call eject_mountable_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
mount_operationA MountOperation
flagsFlags affecting the operation.
Since glibmm 2.24:
void Gio::File::eject_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< MountOperation >&  mount_operation,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Starts an asynchronous eject on a mountable.

When the operation is finished, slot will be called. You can then call eject_mountable_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
mount_operationA MountOperation
flagsFlags affecting the operation.
Since glibmm 2.24:
void Gio::File::eject_mountable ( const Glib::RefPtr< MountOperation >&  mount_operation,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Starts an asynchronous eject on a mountable.

Parameters
mount_operationA MountOperation
flagsFlags affecting the operation.
Since glibmm 2.24:
bool Gio::File::eject_mountable_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes an asynchronous eject operation started by g_file_eject_mountable_with_operation().

Since glibmm 2.22:
Parameters
resultA AsyncResult.
Returns
true if the file was ejected successfully. false otherwise.
Exceptions
Glib::Error
Glib::RefPtr<FileEnumerator> Gio::File::enumerate_children ( const Glib::RefPtr< Cancellable >&  cancellable,
const std::string attributes = "*",
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE 
)

Gets the requested information about the files in a directory.

The result is a FileEnumerator object that will give out FileInfo objects for all the files in the directory.

The attribute value is a string that specifies the file attributes that should be gathered. It is not an error if its not possible to read a particular requested attribute from a file, it just won't be set. attribute should be a comma-separated list of attribute or attribute wildcards. The wildcard "*" means all attributes, and a wildcard like "standard::*" means all attributes in the standard namespace. An example attribute query be "standard::*,owner::user". The standard attributes are availible as defines, like FILE_ATTRIBUTE_STANDARD_NAME.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

If the file does not exist, a Gio::Error with NOT_FOUND will be thrown. If the file is not a directory, a Gio::Error with NOT_DIRECTORY will be thrown. Other errors are possible too.

Parameters
cancellableA Cancellable object.
attributesAn attribute query string.
flagsA set of FileQueryInfoFlags.
Returns
A FileEnumerator if successful.
Glib::RefPtr<FileEnumerator> Gio::File::enumerate_children ( const std::string attributes = "*",
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE 
)

Gets the requested information about the files in a directory.

The result is a FileEnumerator object that will give out FileInfo objects for all the files in the directory.

The attribute value is a string that specifies the file attributes that should be gathered. It is not an error if its not possible to read a particular requested attribute from a file, it just won't be set. attribute should be a comma-separated list of attribute or attribute wildcards. The wildcard "*" means all attributes, and a wildcard like "standard::*" means all attributes in the standard namespace. An example attribute query be "standard::*,owner::user". The standard attributes are availible as defines, like FILE_ATTRIBUTE_STANDARD_NAME.

If the file does not exist, a Gio::Error with NOT_FOUND will be thrown. If the file is not a directory, a Gio::Error with NOT_DIRECTORY will be thrown. Other errors are possible too.

Parameters
attributesAn attribute query string.
flagsA set of FileQueryInfoFlags.
Returns
A FileEnumerator if successful.
void Gio::File::enumerate_children_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const std::string attributes = "*",
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

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 enumerate_children() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call enumerate_children_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
attributesAn attribute query string.
flagsA set of FileQueryInfoFlags.
io_priorityThe I/O priority of the request.
void Gio::File::enumerate_children_async ( const SlotAsyncReady &  slot,
const std::string attributes = "*",
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

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 enumerate_children() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call enumerate_children_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
attributesAn attribute query string.
flagsA set of FileQueryInfoFlags.
io_priorityThe I/O priority of the request.
Glib::RefPtr<FileEnumerator> Gio::File::enumerate_children_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an async enumerate children operation.

See g_file_enumerate_children_async().

Parameters
resA AsyncResult.
Returns
A FileEnumerator or nullptr if an error occurred. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
bool Gio::File::equal ( const Glib::RefPtr< const File >&  other) const

Checks equality of two given Files.

Note that two Files that differ can still refer to the same file on the filesystem due to various forms of filename aliasing.

This call does no blocking I/O.

Parameters
otherThe other File.
Returns
true if * this and other are equal. false if either is not a File.
Glib::RefPtr<Mount> Gio::File::find_enclosing_mount ( const Glib::RefPtr< Cancellable >&  cancellable)

Gets a Mount for the File.

If the FileIface for file does not have a mount (e.g. possibly a remote share), a Gio::Error will be thrown with NOT_FOUND and nullptr will be returned.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
cancellableCancellable object.
Returns
A Mount where the file is located or nullptr on error.
Exceptions
Glib::Error
Glib::RefPtr<Mount> Gio::File::find_enclosing_mount ( )

A find_enclosing_mount() convenience overload.

void Gio::File::find_enclosing_mount_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously gets the mount for the file.

For more details, see find_enclosing_mount() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call find_enclosing_mount_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object.
io_priorityThe I/O priority of the request.
void Gio::File::find_enclosing_mount_async ( const SlotAsyncReady &  slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously gets the mount for the file.

For more details, see find_enclosing_mount() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call find_enclosing_mount_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
io_priorityThe I/O priority of the request.
Glib::RefPtr<Mount> Gio::File::find_enclosing_mount_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an asynchronous find mount request.

See g_file_find_enclosing_mount_async().

Parameters
resA AsyncResult.
Returns
Mount for given file or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
std::string Gio::File::get_basename ( ) const

Gets the base name (the last component of the path) for a given File.

If called for the top level of a system (such as the filesystem root or a uri like sftp://host/) it will return a single directory separator (and on Windows, possibly a drive letter).

The base name is a byte string (not UTF-8). It has no defined encoding or rules other than it may not contain zero bytes. If you want to use filenames in a user interface you should use the display name that you can get by requesting the G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info().

This call does no blocking I/O.

Returns
String containing the File's base name, or nullptr if given File is invalid.
Glib::RefPtr<File> Gio::File::get_child ( const std::string name) const

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 File that points to it. You can use this for instance to create that file.

This call does no blocking I/O.

Parameters
nameString containing the child's basename.
Returns
A File to a child specified by name. Free the returned object with Glib::object_unref().
Glib::RefPtr<File> Gio::File::get_child_for_display_name ( const Glib::ustring display_name) const

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 nullptr and error will be set. This is very useful when constructing a File for a new file and the user entered the filename in the user interface, for instance when you select a directory and type a filename in the file selector.

This call does no blocking I/O.

Parameters
display_nameString to a possible child.
Returns
A File to the specified child, or nullptr if the display name couldn't be converted. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
Glib::RefPtr<File> Gio::File::get_parent ( ) const

Gets the parent directory for the file.

If the file represents the root directory of the file system, then nullptr will be returned.

This call does no blocking I/O.

Returns
A File structure to the parent of the given File or nullptr if there is no parent. Free the returned object with Glib::object_unref().
Glib::ustring Gio::File::get_parse_name ( ) const

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 File back using g_file_parse_name().

This is generally used to show the File as a nice full-pathname kind of string in a user interface, like in a location entry.

For local files with names that can safely be converted to UTF-8 the pathname is used, otherwise the IRI is used (a form of URI that allows UTF-8 characters unescaped).

This call does no blocking I/O.

Returns
A string containing the File's parse name.
std::string Gio::File::get_path ( ) const

Gets the local pathname for File, if one exists.

If non-nullptr, this is guaranteed to be an absolute, canonical path. It might contain symlinks.

This call does no blocking I/O.

Returns
String containing the File's path, or nullptr if no such path exists.
std::string Gio::File::get_relative_path ( const Glib::RefPtr< const File >&  descendant) const

Gets the path for descendant relative to parent.

This call does no blocking I/O.

Parameters
descendantInput File.
Returns
String with the relative path from descendant to parent, or nullptr if descendant doesn't have parent as prefix.
static GType Gio::File::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

std::string Gio::File::get_uri ( ) const

Gets the URI for the file.

This call does no blocking I/O.

Returns
A string containing the File's URI.
std::string Gio::File::get_uri_scheme ( ) const

Gets the URI scheme for a File.

RFC 3986 decodes the scheme as:

[C example ellipted] Common schemes include "file", "http", "ftp", etc.

This call does no blocking I/O.

Returns
A string containing the URI scheme for the given File.
GFile* Gio::File::gobj ( )
inline

Provides access to the underlying C GObject.

const GFile* Gio::File::gobj ( ) const
inline

Provides access to the underlying C GObject.

bool Gio::File::has_parent ( const Glib::RefPtr< File >&  parent) const

Checks if file has a parent, and optionally, if it is parent.

If parent is nullptr then this function returns true if file has any parent at all. If parent is non-nullptr then true is only returned if file is an immediate child of parent.

Since glibmm 2.24:
Parameters
parentThe parent to check for, or nullptr.
Returns
true if file is an immediate child of parent (or any parent in the case that parent is nullptr).
bool Gio::File::has_parent ( ) const

Checks if the file has any parent at all.

Returns
true if the file is a child of any parent.
Since glibmm 2.24:
bool Gio::File::has_prefix ( const Glib::RefPtr< const File >&  prefix) const

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 File 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.

Virtual: prefix_matches

Parameters
prefixInput File.
Returns
true if the file's parent, grandparent, etc is prefix, false otherwise.
bool Gio::File::has_uri_scheme ( const std::string uri_scheme) const

Checks to see if a File has a given URI scheme.

This call does no blocking I/O.

Parameters
uri_schemeA string containing a URI scheme.
Returns
true if File's backend supports the given URI scheme, false if URI scheme is nullptr, not supported, or File is invalid.
guint Gio::File::hash ( ) const

Creates a hash value for a File.

This call does no blocking I/O.

Virtual: hash

Returns
0 if file is not a valid File, otherwise an integer that can be used as hash value for the File. This function is intended for easily hashing a File to add to a HashTable or similar data structure.
bool Gio::File::is_native ( ) const

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.
bool Gio::File::load_contents ( const Glib::RefPtr< Cancellable >&  cancellable,
char *&  contents,
gsize &  length,
std::string etag_out 
)

Loads the content of the file into memory, returning the size of the data.

The data is always zero terminated, but this is not included in the resultant length.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error exception with CANCELLED will be returned.

Parameters
cancellableA cancellable object.
contentsA location to place the contents of the file.
lengthA location to place the length of the contents of the file.
etag_outA location to place the current entity tag for the file.
bool Gio::File::load_contents ( const Glib::RefPtr< Cancellable >&  cancellable,
char *&  contents,
gsize &  length 
)

Loads the content of the file into memory, returning the size of the data.

The data is always zero terminated, but this is not included in the resultant length.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error exception with CANCELLED will be returned.

Parameters
cancellableA cancellable object.
contentsA location to place the contents of the file.
lengthA location to place the length of the contents of the file.
Since glibmm 2.22:
bool Gio::File::load_contents ( char *&  contents,
gsize &  length,
std::string etag_out 
)

Loads the content of the file into memory, returning the size of the data.

The data is always zero terminated, but this is not included in the resultant length.

Parameters
contentsA location to place the contents of the file.
lengthA location to place the length of the contents of the file.
etag_outA location to place the current entity tag for the file.
bool Gio::File::load_contents ( char *&  contents,
gsize &  length 
)

Loads the content of the file into memory, returning the size of the data.

The data is always zero terminated, but this is not included in the resultant length.

Parameters
contentsA location to place the contents of the file.
lengthA location to place the length of the contents of the file.
Since glibmm 2.22:
void Gio::File::load_contents_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Starts an asynchronous load of the file's contents.

For more details, see load_contents() which is the synchronous version of this call.

When the load operation has completed, the slot will be called. To finish the operation, call load_contents_finish() with the AsyncResult provided to the slot.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object.
void Gio::File::load_contents_async ( const SlotAsyncReady &  slot)

Starts an asynchronous load of the file's contents.

For more details, see load_contents() which is the synchronous version of this call.

When the load operation has completed, the slot will be called. To finish the operation, call load_contents_finish() with the AsyncResult provided to the slot.

Parameters
slotA callback slot which will be called when the request is satisfied.
bool Gio::File::load_contents_finish ( const Glib::RefPtr< AsyncResult >&  result,
char *&  contents,
gsize &  length,
std::string etag_out 
)

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. If etag_out is present, it will be set to the new entity tag for the file.

Parameters
resultA AsyncResult.
contentsA location to place the contents of the file.
lengthA location to place the length of the contents of the file.
etag_outA location to place the current entity tag for the file.
Returns
true if the load was successful. If false and error is present, it will be set appropriately.
bool Gio::File::load_contents_finish ( const Glib::RefPtr< AsyncResult >&  result,
char *&  contents,
gsize &  length 
)

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. If etag_out is present, it will be set to the new entity tag for the file.

Parameters
resultA AsyncResult.
contentsA location to place the contents of the file.
lengthA location to place the length of the contents of the file.
Returns
true if the load was successful. If false and error is present, it will be set appropriately.
Since glibmm 2.22:
void Gio::File::load_partial_contents_async ( const SlotReadMore slot_read_more,
const SlotAsyncReady &  slot_async_ready,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Reads the partial contents of a file.

The slot_read_more callback slot should be used to stop reading from the file when appropriate. This operation can be finished by load_partial_contents_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

When the operation is finished, slot will be called. You can then call load_partial_contents_finish() to get the result of the operation.

Parameters
slot_read_moreA callback to receive partial data and to specify whether further data should be read.
slot_async_readyA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
void Gio::File::load_partial_contents_async ( const SlotReadMore slot_read_more,
const SlotAsyncReady &  slot_async_ready 
)

Reads the partial contents of a file.

The slot_read_more callback slot should be used to stop reading from the file when appropriate. This operation can be finished by load_partial_contents_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

When the operation is finished, slot will be called. You can then call load_partial_contents_finish() to get the result of the operation.

Parameters
slot_read_moreA callback to receive partial data and to specify whether further data should be read.
slot_async_readyA callback slot which will be called when the request is satisfied.
bool Gio::File::load_partial_contents_finish ( const Glib::RefPtr< AsyncResult >&  result,
char *&  contents,
gsize &  length,
std::string etag_out 
)

Finishes an asynchronous partial load operation that was started with load_partial_contents_async().

Parameters
resultA AsyncResult.
contentsA location to place the contents of the file.
lengthA location to place the length of the contents of the file.
etag_outA location to place the current entity tag for the file.
Returns
true if the load was successful. If false and error is present, it will be set appropriately.
bool Gio::File::load_partial_contents_finish ( const Glib::RefPtr< AsyncResult >&  result,
char *&  contents,
gsize &  length 
)

Finishes an asynchronous partial load operation that was started with load_partial_contents_async().

Parameters
resultA AsyncResult.
contentsA location to place the contents of the file.
lengthA location to place the length of the contents of the file.
Returns
true if the load was successful. If false and error is present, it will be set appropriately.
Since glibmm 2.22:
bool Gio::File::make_directory ( const Glib::RefPtr< Cancellable >&  cancellable)

Creates a directory.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
cancellableCancellable object.
Returns
true on successful creation, false otherwise.
Exceptions
Glib::Error
bool Gio::File::make_directory ( )

A make_directory() convenience overload.

void Gio::File::make_directory_async ( const SlotAsyncReady &  slot_ready,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously creates a directory.

Parameters
slot_readyA SlotAsyncReady to call when the request is satisfied
cancellableA Cancellable object which can be used to cancel the operation
io_priorityThe I/O priority of the request
Since glibmm 2.38:
void Gio::File::make_directory_async ( const SlotAsyncReady &  slot_ready,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously creates a directory.

Parameters
slot_readyA SlotAsyncReady to call when the request is satisfied
io_priorityThe I/O priority of the request
Since glibmm 2.38:
bool Gio::File::make_directory_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes an asynchronous directory creation, started with g_file_make_directory_async().

Virtual: make_directory_finish

Since glibmm 2.38:
Parameters
resultA AsyncResult.
Returns
true on successful directory creation, false otherwise.
Exceptions
Glib::Error
bool Gio::File::make_directory_with_parents ( const Glib::RefPtr< Cancellable >&  cancellable)

Creates a directory and any parent directories that may not exist similar to 'mkdir -p'.

If the file system does not support creating directories, this function will fail, setting error to Gio::Error::NOT_SUPPORTED. If the directory itself already exists, this function will fail setting error to Gio::Error::EXISTS, unlike the similar Glib::mkdir_with_parents().

For a local File the newly created directories will have the default (current) ownership and permissions of the current process.

If cancellable is not nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio::Error::CANCELLED will be returned.

Since glibmm 2.18:
Parameters
cancellableOptional Cancellable object, nullptr to ignore.
Returns
true if all directories have been successfully created, false otherwise.
Exceptions
Glib::Error
bool Gio::File::make_directory_with_parents ( )

A make_directory_with_parents() convenience overload.

bool Gio::File::make_symbolic_link ( const std::string symlink_value,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Creates a symbolic link.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
symlink_valueA string with the value of the new symlink.
cancellableCancellable object.
Returns
true on the creation of a new symlink, false otherwise.
Exceptions
Glib::Error
bool Gio::File::make_symbolic_link ( const std::string symlink_value)

A make_symbolic_link() convenience overload.

void Gio::File::measure_disk_usage ( const Glib::RefPtr< Cancellable >&  cancellable,
const SlotFileMeasureProgress slot_progress,
guint64 &  disk_usage,
guint64 &  num_dirs,
guint64 &  num_files,
MeasureFlags  flags = MeasureFlags::NONE 
)

Recursively measures the disk usage of the file.

This is essentially an analog of the 'du' command, but it also reports the number of directories and non-directory files encountered (including things like symbolic links).

By default, errors are only reported against the toplevel file itself. Errors found while recursing are silently ignored, unless FILE_DISK_USAGE_REPORT_ALL_ERRORS is given in flags.

The returned size, disk_usage, is in bytes and should be formatted with g_format_size() in order to get something reasonable for showing in a user interface.

slot_progress can be given to request periodic progress updates while scanning. See the documentation for SlotFileMeasureProgress for information about when and how the callback will be invoked.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
cancellableA Cancellable object which can be used to cancel the operation
slot_progressA SlotFileMeasureProgress to call periodically while scanning.
disk_usageThe number of bytes of disk space used.
num_dirsThe number of directories encountered.
num_filesThe number of non-directories encountered.
flagsSet of MeasureFlags.
void Gio::File::measure_disk_usage_async ( const SlotAsyncReady &  slot_ready,
const Glib::RefPtr< Cancellable >&  cancellable,
const SlotFileMeasureProgress slot_progress,
MeasureFlags  flags = MeasureFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Recursively measures the disk usage of the file.

This is the asynchronous version of measure_disk_usage(). See there for more information.

When the operation is finished, slot_ready will be called. You can then call measure_disk_usage_finish() to get the result of the operation.

Parameters
slot_readyA SlotAsyncReady to call when the request is satisfied
cancellableA Cancellable object which can be used to cancel the operation
slot_progressThe callback slot to be called with progress information
flagsSet of MeasureFlags
io_priorityThe I/O priority of the request
bool Gio::File::measure_disk_usage_finish ( const Glib::RefPtr< AsyncResult >&  result,
guint64 &  disk_usage,
guint64 &  num_dirs,
guint64 &  num_files 
)

Collects the results from an earlier call to g_file_measure_disk_usage_async().

See g_file_measure_disk_usage() for more information.

Since glibmm 2.38:
Parameters
resultThe AsyncResult passed to your SlotAsyncReady.
disk_usageThe number of bytes of disk space used.
num_dirsThe number of directories encountered.
num_filesThe number of non-directories encountered.
Returns
true if successful, with the out parameters set. false otherwise, with error set.
Exceptions
Glib::Error
Glib::RefPtr<FileMonitor> Gio::File::monitor ( const Glib::RefPtr< Cancellable >&  cancellable,
FileMonitorFlags  flags = FileMonitorFlags::NONE 
)

Obtains a file monitor for the given file.

If no file notification mechanism exists, then regular polling of the file is used.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
cancellableA Cancellable object.
flagsA set of FileMonitorFlags.
Returns
A FileMonitor for the file.
Since glibmm 2.18:

Obtains a file monitor for the given file.

If no file notification mechanism exists, then regular polling of the file is used.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
flagsA set of FileMonitorFlags.
Returns
A FileMonitor for the file.
Since glibmm 2.18:
Glib::RefPtr<FileMonitor> Gio::File::monitor_directory ( const Glib::RefPtr< Cancellable >&  cancellable,
FileMonitorFlags  flags = FileMonitorFlags::NONE 
)

Obtains a directory monitor for the given file.

This may fail if directory monitoring is not supported.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
cancellableA Cancellable object.
flagsA set of FileMonitorFlags.
Returns
A FileMonitor for the file.
Glib::RefPtr<FileMonitor> Gio::File::monitor_directory ( FileMonitorFlags  flags = FileMonitorFlags::NONE)

Obtains a directory monitor for the given file.

This may fail if directory monitoring is not supported.

Parameters
flagsA set of FileMonitorFlags.
Returns
A FileMonitor for the file.
Glib::RefPtr<FileMonitor> Gio::File::monitor_file ( const Glib::RefPtr< Cancellable >&  cancellable,
FileMonitorFlags  flags = FileMonitorFlags::NONE 
)

Obtains a file monitor for the given file.

If no file notification mechanism exists, then regular polling of the file is used.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
cancellableA Cancellable object.
flagsA set of FileMonitorFlags.
Returns
A FileMonitor for the file.
Glib::RefPtr<FileMonitor> Gio::File::monitor_file ( FileMonitorFlags  flags = FileMonitorFlags::NONE)

Obtains a file monitor for the given file.

If no file notification mechanism exists, then regular polling of the file is used.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
flagsA set of FileMonitorFlags.
Returns
A FileMonitor for the file.
void Gio::File::mount_enclosing_volume ( const Glib::RefPtr< MountOperation >&  mount_operation,
const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
Mount::MountFlags  flags = Mount::MountFlags::NONE 
)

Starts a mount_operation, mounting the volume that contains the file.

When this operation has completed, slot will be called with, and the operation can be finalized with mount_enclosing_volume_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
mount_operationA MountOperation.
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object.
flagsFlags affecting the operation.
void Gio::File::mount_enclosing_volume ( const Glib::RefPtr< MountOperation >&  mount_operation,
const SlotAsyncReady &  slot,
Mount::MountFlags  flags = Mount::MountFlags::NONE 
)

Starts a mount_operation, mounting the volume that contains the file.

When this operation has completed, slot will be called with, and the operation can be finalized with mount_enclosing_volume_finish().

Parameters
mount_operationA MountOperation.
slotA callback slot which will be called when the request is satisfied.
flagsFlags affecting the operation.
void Gio::File::mount_enclosing_volume ( const SlotAsyncReady &  slot,
Mount::MountFlags  flags = Mount::MountFlags::NONE 
)

Starts a mount_operation, mounting the volume that contains the file.

When this operation has completed, slot will be called with, and the operation can be finalized with mount_enclosing_volume_finish().

Parameters
slotA callback slot which will be called when the request is satisfied.
flagsFlags affecting the operation.
void Gio::File::mount_enclosing_volume ( Mount::MountFlags  flags = Mount::MountFlags::NONE)

Starts a mount_operation, mounting the volume that contains the file.

Parameters
flagsFlags affecting the operation.
bool Gio::File::mount_enclosing_volume_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes a mount operation started by g_file_mount_enclosing_volume().

Parameters
resultA AsyncResult.
Returns
true if successful. If an error has occurred, this function will return false and set error appropriately if present.
Exceptions
Glib::Error
void Gio::File::mount_mountable ( const Glib::RefPtr< MountOperation >&  mount_operation,
const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
Mount::MountFlags  flags = Mount::MountFlags::NONE 
)

Mounts a file of type FILE_TYPE_MOUNTABLE.

Using mount_operation, you can request callbacks when, for instance, passwords are needed during authentication.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

When the operation is finished, slot will be called. You can then call mount_mountable_finish() to get the result of the operation.

Parameters
mount_operationA MountOperation.
cancellableA Cancellable object which can be used to cancel the operation.
slotA callback slot which will be called when the request is satisfied.
flagsFlags affecting the operation.
void Gio::File::mount_mountable ( const Glib::RefPtr< MountOperation >&  mount_operation,
const SlotAsyncReady &  slot,
Mount::MountFlags  flags = Mount::MountFlags::NONE 
)

Mounts a file of type FILE_TYPE_MOUNTABLE.

Using mount_operation, you can request callbacks when, for instance, passwords are needed during authentication.

When the operation is finished, slot will be called. You can then call mount_mountable_finish() to get the result of the operation.

Parameters
mount_operationA MountOperation.
slotA callback slot which will be called when the request is satisfied.
flagsFlags affecting the operation.
void Gio::File::mount_mountable ( const SlotAsyncReady &  slot,
Mount::MountFlags  flags = Mount::MountFlags::NONE 
)

Mounts a file of type FILE_TYPE_MOUNTABLE without user interaction.

When the operation is finished, slot will be called. You can then call mount_mountable_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
flagsFlags affecting the operation.
void Gio::File::mount_mountable ( Mount::MountFlags  flags = Mount::MountFlags::NONE)

Mounts a file of type FILE_TYPE_MOUNTABLE without user interaction.

Parameters
flagsFlags affecting the operation.
Glib::RefPtr<File> Gio::File::mount_mountable_finish ( const Glib::RefPtr< AsyncResult >&  result)

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
resultA AsyncResult.
Returns
A File or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
bool Gio::File::move ( const Glib::RefPtr< File >&  destination,
const SlotFileProgress slot,
const Glib::RefPtr< Cancellable >&  cancellable,
CopyFlags  flags = CopyFlags::NONE 
)

Tries to move the file or directory source to the location specified by destination.

If native move operations are supported then this is used, otherwise a copy and delete fallback is used. The native implementation may support moving directories (for instance on moves inside the same filesystem), but the fallback code does not.

If the flag CopyFlags::OVERWRITE is specified an already existing destination file is overwritten.

If the flag CopyFlags::NOFOLLOW_SYMLINKS is specified then symlinks will be copied as symlinks, otherwise the target of the source symlink will be copied.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

The operation can be monitored via the slot callback. If the source file does not exist then a Gio::Error with NOT_FOUND will be thrown, independent on the status of the destination.

If G_CopyFlags::OVERWRITE is not specified and the target exists, then a Gio::Error with EXISTS will be thrown.

If trying to overwrite a file over a directory a Gio::Error with IS_DIRECTORY will be thrown. If trying to overwrite a directory with a directory a Gio::Error with WOULD_MERGE will be thrown.

If the source is a directory and the target does not exist, or CopyFlags::OVERWRITE is specified and the target is a file, then a Gio::Error with WOULD_RECURSE may be thrown (if the native move operation isn't available).

bool Gio::File::move ( const Glib::RefPtr< File >&  destination,
const SlotFileProgress slot,
CopyFlags  flags = CopyFlags::NONE 
)
bool Gio::File::move ( const Glib::RefPtr< File >&  destination,
CopyFlags  flags = CopyFlags::NONE 
)
Glib::RefPtr<FileIOStream> Gio::File::open_readwrite ( const Glib::RefPtr< Cancellable >&  cancellable)

Opens an existing file for reading and writing.

The result is a FileIOStream that can be used to read and write the contents of the file.

If cancellable is not nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio::Error::CANCELLED will be returned.

If the file does not exist, the Gio::Error::NOT_FOUND error will be returned. If the file is a directory, the Gio::Error::IS_DIRECTORY error will be returned. Other errors are possible too, and depend on what kind of filesystem the file is on. 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.

Since glibmm 2.22:
Parameters
cancellableA Cancellable.
Returns
FileIOStream or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
Glib::RefPtr<FileIOStream> Gio::File::open_readwrite ( )

A open_readwrite() convenience overload.

void Gio::File::open_readwrite_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Opens an existing file for reading and writing.

The result is a FileIOStream that can be used to read and write the contents of the file.

For more details, see open_readwrite() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call open_readwrite_finish() to get the result of the operation. If the file does not exist, a Gio::Error with NOT_FOUND will be thrown. If the file is a directory, a Gio::Error with IS_DIRECTORY will be thrown. 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
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
io_priorityThe I/O priority of the request.
Since glibmm 2.24:
void Gio::File::open_readwrite_async ( const SlotAsyncReady &  slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Opens an existing file for reading and writing.

The result is a FileIOStream that can be used to read and write the contents of the file.

For more details, see open_readwrite() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call open_readwrite_finish() to get the result of the operation. If the file does not exist, a Gio::Error with NOT_FOUND will be thrown. If the file is a directory, a Gio::Error with IS_DIRECTORY will be thrown. 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
slotA callback slot which will be called when the request is satisfied.
io_priorityThe I/O priority of the request.
Since glibmm 2.24:
Glib::RefPtr<FileIOStream> Gio::File::open_readwrite_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an asynchronous file read operation started with g_file_open_readwrite_async().

Since glibmm 2.22:
Parameters
resA AsyncResult.
Returns
A FileIOStream or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
File& Gio::File::operator= ( File&&  src)
noexcept
void Gio::File::poll_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Polls a file of type Mountable.

Using start_operation, you can request callbacks when, for instance, passwords are needed during authentication.

When this operation has completed, slot will be called and the operation can be finalized with stop_mountable_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
slotA callback to call when the request is satisfied.
cancellableA Cancellable object.
Since glibmm 2.24:
void Gio::File::poll_mountable ( const SlotAsyncReady &  slot)

Polls a file of type Mountable.

Using start_operation, you can request callbacks when, for instance, passwords are needed during authentication.

When this operation has completed, slot will be called and the operation can be finalized with stop_mountable_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
slotA callback to call when the request is satisfied.
Since glibmm 2.24:
bool Gio::File::poll_mountable_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes a poll operation.

See g_file_poll_mountable() for details.

Finish an asynchronous poll operation that was polled with g_file_poll_mountable().

Since glibmm 2.22:
Parameters
resultA AsyncResult.
Returns
true if the operation finished successfully. false otherwise.
Exceptions
Glib::Error
Glib::RefPtr<AppInfo> Gio::File::query_default_handler ( const Glib::RefPtr< Cancellable >&  cancellable)

Returns the AppInfo that is registered as the default application to handle the file specified by file.

If cancellable is not nullptr, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error Gio::Error::CANCELLED will be returned.

Parameters
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A AppInfo if the handle was found, nullptr if there were errors. When you are done with it, release it with Glib::object_unref().
Exceptions
Glib::Error
Glib::RefPtr<AppInfo> Gio::File::query_default_handler ( )

A query_default_handler() convenience overload.

bool Gio::File::query_exists ( const Glib::RefPtr< Cancellable >&  cancellable) const

Utility function to check if a particular file exists.

This is implemented using query_info() and as such does blocking I/O.

Note that in many cases it is racy to first check for file existence and then execute something based on the outcome of that, because the file might have been created or removed in between the operations. The general approach to handling that is to not check, but just do the operation and handle the errors as they come.

As an example of race-free checking, take the case of reading a file, and if it doesn't exist, creating it. There are two racy versions: read it, and on error create it; and: check if it exists, if not create it. These can both result in two processes creating the file (with perhaps a partially written file as the result). The correct approach is to always try to create the file with File::create() which will either atomically create the file or fail with a Gio::Error exception with EXISTS.

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.

Parameters
cancellableOptional Cancellable object, nullptr to ignore.
Returns
true if the file exists (and can be detected without error), false otherwise (or if cancelled).
bool Gio::File::query_exists ( ) const

A query_exists() convenience overload.

FileType Gio::File::query_file_type ( FileQueryInfoFlags  flags,
const Glib::RefPtr< Cancellable >&  cancellable 
) const

Utility function to inspect the FileType 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.

Since glibmm 2.18:
Parameters
flagsA set of FileQueryInfoFlags passed to g_file_query_info().
cancellableOptional Cancellable object, nullptr to ignore.
Returns
The FileType of the file and Gio::FileType::UNKNOWN if the file does not exist.
FileType Gio::File::query_file_type ( FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE) const

Utility function to inspect the FileType of a file.

This is implemented using 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
flagsa set of FileQueryInfoFlags passed to query_info().
Returns
The FileType of the file, or FILE_TYPE_UNKNOWN if the file does not exist.
Since glibmm 2.18:
Glib::RefPtr<FileInfo> Gio::File::query_filesystem_info ( const Glib::RefPtr< Cancellable >&  cancellable,
const std::string attributes = "*" 
)

Similar to query_info(), but obtains information about the filesystem the file is on, rather than the file itself.

For instance the amount of space availible and the type of the filesystem.

The attribute value is a string that specifies the file attributes that should be gathered. It is not an error if its not possible to read a particular requested attribute from a file, it just won't be set. attribute should be a comma-separated list of attribute or attribute wildcards. The wildcard "*" means all attributes, and a wildcard like "fs:*" means all attributes in the fs namespace. The standard namespace for filesystem attributes is "fs". Common attributes of interest are FILE_ATTRIBUTE_FILESYSTEM_SIZE (the total size of the filesystem in bytes), FILE_ATTRIBUTE_FILESYSTEM_FREE (number of bytes availible), and FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

If the file does not exist, a Gio::Error with NOT_FOUND will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
cancellableA Cancellable object.
attributesAn attribute query string.
Returns
A FileInfo or an empty RefPtr if there was an error.
Glib::RefPtr<FileInfo> Gio::File::query_filesystem_info ( const std::string attributes = "*")

Similar to query_info(), but obtains information about the filesystem the file is on, rather than the file itself.

For instance the amount of space availible and the type of the filesystem.

The attribute value is a string that specifies the file attributes that should be gathered. It is not an error if its not possible to read a particular requested attribute from a file, it just won't be set. attribute should be a comma-separated list of attribute or attribute wildcards. The wildcard "*" means all attributes, and a wildcard like "fs:*" means all attributes in the fs namespace. The standard namespace for filesystem attributes is "fs". Common attributes of interest are FILE_ATTRIBUTE_FILESYSTEM_SIZE (the total size of the filesystem in bytes), FILE_ATTRIBUTE_FILESYSTEM_FREE (number of bytes availible), and FILE_ATTRIBUTE_FILESYSTEM_TYPE (type of the filesystem).

If the file does not exist, a Gio::Error with NOT_FOUND will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
attributesAn attribute query string.
Returns
A FileInfo or an empty RefPtr if there was an error.
void Gio::File::query_filesystem_info_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const std::string attributes = "*",
int  io_priority = Glib::PRIORITY_DEFAULT 
) const

Asynchronously gets the requested information about the filesystem that the file is on.

The result is a FileInfo object that contains key-value attributes (such as type or size for the file).

For more details, see query_filesystem_info() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call query_filesystem_info_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
attributesAn attribute query string.
io_priorityThe I/O priority of the request.
void Gio::File::query_filesystem_info_async ( const SlotAsyncReady &  slot,
const std::string attributes = "*",
int  io_priority = Glib::PRIORITY_DEFAULT 
) const

Asynchronously gets the requested information about the filesystem that the file is on.

The result is a FileInfo object that contains key-value attributes (such as type or size for the file).

For more details, see query_filesystem_info() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call query_filesystem_info_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
attributesAn attribute query string.
io_priorityThe I/O priority of the request.
Glib::RefPtr<FileInfo> Gio::File::query_filesystem_info_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an asynchronous filesystem info query.

See g_file_query_filesystem_info_async().

Parameters
resA AsyncResult.
Returns
FileInfo for given file or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
Glib::RefPtr<FileInfo> Gio::File::query_info ( const Glib::RefPtr< Cancellable >&  cancellable,
const std::string attributes = "*",
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE 
) const

Gets the requested information about the file.

The result is a FileInfo object that contains key-value attributes (such as the type or size of the file).

The attribute value is a string that specifies the file attributes that should be gathered. It is not an error if it's not possible to read a particular requested attribute from a file - it just won't be set. attribute should be a comma-separated list of attribute or attribute wildcards. The wildcard "*" means all attributes, and a wildcard like "standard::*" means all attributes in the standard namespace. An example attribute query be "standard::*,owner::user". The standard attributes are available as defines, like G_FILE_ATTRIBUTE_STANDARD_NAME.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

For symlinks, normally the information about the target of the symlink is returned, rather than information about the symlink itself. However if you pass FileQueryInfoFlags::NOFOLLOW_SYMLINKS in flags the information about the symlink itself will be returned. Also, for symlinks that point to non-existing files the information about the symlink itself will be returned.

If the file does not exist, a Gio::Error with NOT_FOUND will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
cancellableA Cancellable object.
attributesAn attribute query string.
flagsA set of FileQueryInfoFlags.
Returns
a FileInfo for the file, or an empty RefPtr on error.
Glib::RefPtr<FileInfo> Gio::File::query_info ( const std::string attributes = "*",
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE 
) const

Gets the requested information about the file.

The result is a FileInfo object that contains key-value attributes (such as the type or size of the file).

The attribute value is a string that specifies the file attributes that should be gathered. It is not an error if it's not possible to read a particular requested attribute from a file - it just won't be set. attribute should be a comma-separated list of attribute or attribute wildcards. The wildcard "*" means all attributes, and a wildcard like "standard::*" means all attributes in the standard namespace. An example attribute query be "standard::*,owner::user". The standard attributes are available as defines, like G_FILE_ATTRIBUTE_STANDARD_NAME.

For symlinks, normally the information about the target of the symlink is returned, rather than information about the symlink itself. However if you pass FileQueryInfoFlags::NOFOLLOW_SYMLINKS in flags the information about the symlink itself will be returned. Also, for symlinks that point to non-existing files the information about the symlink itself will be returned.

If the file does not exist, a Gio::Error with NOT_FOUND will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
attributesAn attribute query string.
flagsA set of FileQueryInfoFlags.
Returns
a FileInfo for the file, or an empty RefPtr on error.
void Gio::File::query_info_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const std::string attributes = "*",
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
) const

Asynchronously gets the requested information about specified file.

The result is a FileInfo object that contains key-value attributes (such as type or size for the file).

For more details, see query_info() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call query_info_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
attributesAn attribute query string.
flagsA set of FileQueryInfoFlags.
io_priorityThe I/O priority of the request.
void Gio::File::query_info_async ( const SlotAsyncReady &  slot,
const std::string attributes = "*",
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
) const

Asynchronously gets the requested information about specified file.

The result is a FileInfo object that contains key-value attributes (such as type or size for the file).

For more details, see query_info() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call query_info_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
attributesAn attribute query string.
flagsA set of FileQueryInfoFlags.
io_priorityThe I/O priority of the request.
Glib::RefPtr<FileInfo> Gio::File::query_info_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an asynchronous file info query.

See g_file_query_info_async().

Parameters
resA AsyncResult.
Returns
FileInfo for given file or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
Glib::RefPtr<FileAttributeInfoList> Gio::File::query_settable_attributes ( const Glib::RefPtr< Cancellable >&  cancellable)

Obtain the list of settable attributes for the file.

Parameters
cancellableOptional Cancellable object, nullptr to ignore.
Returns
A FileAttributeInfoList describing the settable attributes. When you are done with it, release it with g_file_attribute_info_list_unref().
Exceptions
Glib::Error
Glib::RefPtr<FileAttributeInfoList> Gio::File::query_settable_attributes ( )

A query_settable_attributes() convenience overload.

Glib::RefPtr<FileAttributeInfoList> Gio::File::query_writable_namespaces ( const Glib::RefPtr< Cancellable >&  cancellable)

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).

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
cancellableCancellable object.
Returns
A FileAttributeInfoList describing the writable namespaces. When you are done with it, release it with g_file_attribute_info_list_unref().
Exceptions
Glib::Error
Glib::RefPtr<FileAttributeInfoList> Gio::File::query_writable_namespaces ( )

A query_writable_namespaces() convenience overload.

Glib::RefPtr<FileInputStream> Gio::File::read ( const Glib::RefPtr< Cancellable >&  cancellable)

Opens a file for reading.

The result is a FileInputStream that can be used to read the contents of the file.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

If the file does not exist, a Gio::Error with NOT_FOUND will be thrown. If the file is a directory, a Gio::Error with IS_DIRECTORY will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
cancellableA Cancellable.
Returns
FileInputStream or nullptr on error.
Exceptions
Glib::Error
Glib::RefPtr<FileInputStream> Gio::File::read ( )

A read() convenience overload.

void Gio::File::read_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously opens the file for reading.

For more details, see read() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call read_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
io_priorityThe I/O priority of the request.
void Gio::File::read_async ( const SlotAsyncReady &  slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously opens the file for reading.

For more details, see read() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call read_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
io_priorityThe I/O priority of the request.
Glib::RefPtr<FileInputStream> Gio::File::read_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an asynchronous file read operation started with g_file_read_async().

Parameters
resA AsyncResult.
Returns
A FileInputStream or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
bool Gio::File::remove ( const Glib::RefPtr< Cancellable >&  cancellable)

Deletes a file.

If the file is a directory, it will only be deleted if it is empty. The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
cancellableA Cancellable object which can be used to cancel the operation.
Returns
true if the file was deleted. false otherwise.
bool Gio::File::remove ( )

A remove() convenience overload.

void Gio::File::remove_async ( const SlotAsyncReady &  slot_ready,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

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
slot_readyA SlotAsyncReady to call when the request is satisfied
cancellableA Cancellable object which can be used to cancel the operation
io_priorityThe I/O priority of the request
Since glibmm 2.34:
void Gio::File::remove_async ( const SlotAsyncReady &  slot_ready,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

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
slot_readyA SlotAsyncReady to call when the request is satisfied
io_priorityThe I/O priority of the request
Since glibmm 2.34:
bool Gio::File::remove_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes deleting a file started with g_file_delete_async().

Virtual: delete_file_finish

Since glibmm 2.34:
Parameters
resultA AsyncResult.
Returns
true if the file was deleted. false otherwise.
Exceptions
Glib::Error
Glib::RefPtr<FileOutputStream> Gio::File::replace ( const Glib::RefPtr< Cancellable >&  cancellable,
const std::string etag = {},
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Returns an output stream for overwriting the file, possibly creating a backup copy of the file first.

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 CreateFlags::PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

If you pass in an etag value, then this value is compared to the current entity tag of the file, and if they differ a Gio::Error with WRONG_ETAG will be thrown. This generally means that the file has been changed since you last read it. You can get the new etag from FileOutputStream::get_etag() after you've finished writing and closed the FileOutputStream. When you load a new file you can use FileInputStream::query_info() to get the etag of the file.

If make_backup is true, this function will attempt to make a backup of the current file before overwriting it. If this fails aa Gio::Error with CANT_CREATE_BACKUP will be thrown. If you want to replace anyway, try again with make_backup set to false.

If the file is a directory a Gio::Error with IS_DIRECTORY will be thrown, and if the file is some other form of non-regular file then aa Gio::Error with NOT_REGULAR_FILE will be thrown. Some file systems don't allow all file names, and may throw a Gio::Error with INVALID_FILENAME, and if the name is to longa Gio::Error with FILENAME_TOO_LONG will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
cancellableA Cancellable object which can be used to cancel the operation.
etagAn optional entity tag for the current Glib::File.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
Returns
A FileOutputStream.
Glib::RefPtr<FileOutputStream> Gio::File::replace ( const std::string etag = {},
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Returns an output stream for overwriting the file, possibly creating a backup copy of the file first.

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 CreateFlags::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 you pass in an etag value, then this value is compared to the current entity tag of the file, and if they differ a Gio::Error with WRONG_ETAG will be thrown. This generally means that the file has been changed since you last read it. You can get the new etag from FileOutputStream::get_etag() after you've finished writing and closed the FileOutputStream. When you load a new file you can use FileInputStream::query_info() to get the etag of the file.

If make_backup is true, this function will attempt to make a backup of the current file before overwriting it. If this fails aa Gio::Error with CANT_CREATE_BACKUP will be thrown. If you want to replace anyway, try again with make_backup set to false.

If the file is a directory a Gio::Error with IS_DIRECTORY will be thrown, and if the file is some other form of non-regular file then aa Gio::Error with NOT_REGULAR_FILE will be thrown. Some file systems don't allow all file names, and may throw a Gio::Error with INVALID_FILENAME, and if the name is to longa Gio::Error with FILENAME_TOO_LONG will be thrown. Other errors are possible too, and depend on what kind of filesystem the file is on.

Parameters
etagAn optional entity tag for the current Glib::File.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
Returns
A FileOutputStream.
void Gio::File::replace_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const std::string etag = {},
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asyncronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first.

For more details, see replace() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call replace_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
etagAn entity tag for the current Gio::File.
make_backuptrue if a backup of the existing file should be made.
flagsA set of CreateFlags.
io_priorityThe I/O priority of the request.
void Gio::File::replace_async ( const SlotAsyncReady &  slot,
const std::string etag = {},
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asyncronously overwrites the file, replacing the contents, possibly creating a backup copy of the file first.

For more details, see replace() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call replace_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
etagAn entity tag for the current Gio::File.
make_backuptrue if a backup of the existing file should be made.
flagsA set of CreateFlags.
io_priorityThe I/O priority of the request.
void Gio::File::replace_contents ( const char *  contents,
gsize  length,
const std::string etag,
std::string new_etag,
const Glib::RefPtr< Cancellable >&  cancellable,
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Replaces the contents of the file with contents of length bytes.

If etag is specified (not an empty string) any existing file must have that etag, or a Gio::Error with WRONG_ETAG will be thrown.

If make_backup is true, this function will attempt to make a backup of the file.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

The returned new_etag can be used to verify that the file hasn't changed the next time it is saved over.

Parameters
contentsA string containing the new contents for the file.
lengthThe length of contents in bytes.
etagThe old entity tag for the document.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
new_etagA location to a new entity tag for the document.
cancellableA Cancellable object.
void Gio::File::replace_contents ( const char *  contents,
gsize  length,
const std::string etag,
std::string new_etag,
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Replaces the contents of the file with contents of length bytes.

If etag is specified (not an empty string) any existing file must have that etag, or a Gio::Error with WRONG_ETAG will be thrown.

If make_backup is true, this function will attempt to make a backup of the file.

The returned new_etag can be used to verify that the file hasn't changed the next time it is saved over.

Parameters
contentsA string containing the new contents for the file.
lengthThe length of contents in bytes.
etagThe old entity tag for the document.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
new_etagA location to a new entity tag for the document.
void Gio::File::replace_contents ( const std::string contents,
const std::string etag,
std::string new_etag,
const Glib::RefPtr< Cancellable >&  cancellable,
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Replaces the contents of the file with contents.

If etag is specified (not an empty string) any existing file must have that etag, or a Gio::Error with WRONG_ETAG will be thrown.

If make_backup is true, this function will attempt to make a backup of the file.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

The returned new_etag can be used to verify that the file hasn't changed the next time it is saved over.

Parameters
contentsA string containing the new contents for the file.
etagThe old entity tag for the document.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
new_etagA location to a new entity tag for the document.
cancellableA Cancellable object.
void Gio::File::replace_contents ( const std::string contents,
const std::string etag,
std::string new_etag,
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Replaces the contents of the file with contents.

If etag is specified (not an empty string) any existing file must have that etag, or a Gio::Error with WRONG_ETAG will be thrown.

If make_backup is true, this function will attempt to make a backup of the file.

The returned new_etag can be used to verify that the file hasn't changed the next time it is saved over.

Parameters
contentsA string containing the new contents for the file.
etagThe old entity tag for the document.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
new_etagA location to a new entity tag for the document.
void Gio::File::replace_contents_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const char *  contents,
gsize  length,
const std::string etag,
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Starts an asynchronous replacement of the file with the given contents of length bytes.

etag will replace the document's current entity tag.

When this operation has completed, slot will be called and the operation can be finalized with replace_contents_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

If make_backup is true, this function will attempt to make a backup of the file.

Parameters
slotA callback to call when the request is satisfied.
cancellableA Cancellable object.
contentsString of contents to replace the file with.
lengthThe length of contents in bytes.
etaga new entity tag for the file.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
void Gio::File::replace_contents_async ( const SlotAsyncReady &  slot,
const char *  contents,
gsize  length,
const std::string etag,
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Starts an asynchronous replacement of the file with the given contents of length bytes.

etag will replace the document's current entity tag.

When this operation has completed, slot will be called and the operation can be finalized with replace_contents_finish().

If make_backup is true, this function will attempt to make a backup of the file.

Parameters
slotA callback to call when the request is satisfied.
contentsString of contents to replace the file with.
lengthThe length of contents in bytes.
etaga new entity tag for the file.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
void Gio::File::replace_contents_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const std::string contents,
const std::string etag,
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Starts an asynchronous replacement of the file with the given contents of length bytes.

etag will replace the document's current entity tag.

When this operation has completed, slot will be called and the operation can be finalized with replace_contents_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

If make_backup is true, this function will attempt to make a backup of the file.

Parameters
slotA callback to call when the request is satisfied.
cancellableA Cancellable object.
contentsString of contents to replace the file with.
etaga new entity tag for the file.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
void Gio::File::replace_contents_async ( const SlotAsyncReady &  slot,
const std::string contents,
const std::string etag,
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Starts an asynchronous replacement of the file with the given contents.

etag will replace the document's current entity tag.

When this operation has completed, slot will be called and the operation can be finalized with replace_contents_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

If make_backup is true, this function will attempt to make a backup of the file.

Parameters
slotA callback to call when the request is satisfied.
contentsString of contents to replace the file with.
etaga new entity tag for the file.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
void Gio::File::replace_contents_bytes_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const Glib::RefPtr< const Glib::Bytes >&  contents,
const std::string etag,
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Same as replace_contents_async() but takes a Gio::Bytes input instead.

When this operation has completed, slot will be called and the operation can be finalized with replace_contents_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

If make_backup is true, this function will attempt to make a backup of the file.

Parameters
slotA callback to call when the request is satisfied.
cancellableA Cancellable object.
contentsBytes of contents to replace the file with.
etaga new entity tag for the file.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
void Gio::File::replace_contents_bytes_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< const Glib::Bytes >&  contents,
const std::string etag,
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

Same as replace_contents_async() but takes a Gio::Bytes input instead.

When this operation has completed, slot will be called and the operation can be finalized with replace_contents_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

If make_backup is true, this function will attempt to make a backup of the file.

Parameters
slotA callback to call when the request is satisfied.
contentsBytes of contents to replace the file with.
etaga new entity tag for the file.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
void Gio::File::replace_contents_finish ( const Glib::RefPtr< AsyncResult >&  result,
std::string new_etag 
)

Finishes an asynchronous replace of the given file .

See replace_contents_async(). Sets new_etag to the new entity tag for the document.

Parameters
resultA AsyncResult.
new_etagA location of a new entity tag for the document.
void Gio::File::replace_contents_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes an asynchronous replace of the given file .

See replace_contents_async(). Sets new_etag to the new entity tag for the document.

Parameters
resultA AsyncResult. for the document.
Glib::RefPtr<FileOutputStream> Gio::File::replace_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an asynchronous file replace operation started with g_file_replace_async().

Parameters
resA AsyncResult.
Returns
A FileOutputStream, or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
Glib::RefPtr<FileIOStream> Gio::File::replace_readwrite ( const Glib::RefPtr< Cancellable >&  cancellable,
const std::string etag = {},
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

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 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
cancellableA Cancellable object which can be used to cancel the operation.
etagAn optional entity tag for the current Glib::File.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
Returns
A FileOutputStream.
Since glibmm 2.24:
Glib::RefPtr<FileIOStream> Gio::File::replace_readwrite ( const std::string etag = {},
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE 
)

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 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
etagAn optional entity tag for the current Glib::File.
make_backuptrue if a backup should be created.
flagsA set of CreateFlags.
Returns
A FileOutputStream.
Since glibmm 2.24:
void Gio::File::replace_readwrite_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const std::string etag = {},
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asyncronously overwrites the file in read-write mode, replacing the contents, possibly creating a backup copy of the file first.

For more details, see replace_readwrite() which is the synchronous version of this call.

When the operation is finished, slot will be called. You can then call replace_readwrite_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
etagAn entity tag for the current Gio::File.
make_backuptrue if a backup of the existing file should be made.
flagsA set of CreateFlags.
io_priorityThe I/O priority of the request.
Since glibmm 2.24:
void Gio::File::replace_readwrite_async ( const SlotAsyncReady &  slot,
const std::string etag = {},
bool  make_backup = false,
CreateFlags  flags = CreateFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asyncronously overwrites the file in read-write mode, replacing the contents, possibly creating a backup copy of the file first.

For more details, see replace_readwrite() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call replace_readwrite_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
etagAn entity tag for the current Gio::File.
make_backuptrue if a backup of the existing file should be made.
flagsA set of CreateFlags.
io_priorityThe I/O priority of the request.
Since glibmm 2.24:
Glib::RefPtr<FileIOStream> Gio::File::replace_readwrite_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes an asynchronous file replace operation started with g_file_replace_readwrite_async().

Since glibmm 2.22:
Parameters
resA AsyncResult.
Returns
A FileIOStream, or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
Glib::RefPtr<File> Gio::File::resolve_relative_path ( const std::string relative_path) const

Resolves a relative path for file to an absolute path.

This call does no blocking I/O.

Parameters
relative_pathA given relative path string.
Returns
File to the resolved path. nullptr if relative_path is nullptr or if file is invalid. Free the returned object with Glib::object_unref().
bool Gio::File::set_attribute_byte_string ( const std::string attribute,
const std::string value,
FileQueryInfoFlags  flags,
const Glib::RefPtr< Cancellable >&  cancellable 
)

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.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
attributeA string containing the attribute's name.
valueA string containing the attribute's new value.
flagsA FileQueryInfoFlags.
cancellableCancellable object.
Returns
true if the attribute was successfully set to value in the file, false otherwise.
Exceptions
Glib::Error
bool Gio::File::set_attribute_byte_string ( const std::string attribute,
const std::string value,
FileQueryInfoFlags  flags 
)

A set_attribute_byte_string() convenience overload.

bool Gio::File::set_attribute_int32 ( const std::string attribute,
gint32  value,
FileQueryInfoFlags  flags,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Sets attribute of type G_FILE_ATTRIBUTE_TYPE_INT32 to value.

If attribute is of a different type, this operation will fail.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
attributeA string containing the attribute's name.
valueA #gint32 containing the attribute's new value.
flagsA FileQueryInfoFlags.
cancellableCancellable object.
Returns
true if the attribute was successfully set to value in the file, false otherwise.
Exceptions
Glib::Error
bool Gio::File::set_attribute_int32 ( const std::string attribute,
gint32  value,
FileQueryInfoFlags  flags 
)

A set_attribute_int32() convenience overload.

bool Gio::File::set_attribute_int64 ( const std::string attribute,
gint64  value,
FileQueryInfoFlags  flags,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Sets attribute of type G_FILE_ATTRIBUTE_TYPE_INT64 to value.

If attribute is of a different type, this operation will fail.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
attributeA string containing the attribute's name.
valueA #guint64 containing the attribute's new value.
flagsA FileQueryInfoFlags.
cancellableCancellable object.
Returns
true if the attribute was successfully set, false otherwise.
Exceptions
Glib::Error
bool Gio::File::set_attribute_int64 ( const std::string attribute,
gint64  value,
FileQueryInfoFlags  flags 
)

A set_attribute_int64() convenience overload.

bool Gio::File::set_attribute_string ( const std::string attribute,
const Glib::ustring value,
FileQueryInfoFlags  flags,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Sets attribute of type G_FILE_ATTRIBUTE_TYPE_STRING to value.

If attribute is of a different type, this operation will fail.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
attributeA string containing the attribute's name.
valueA string containing the attribute's value.
flagsFileQueryInfoFlags.
cancellableCancellable object.
Returns
true if the attribute was successfully set, false otherwise.
Exceptions
Glib::Error
bool Gio::File::set_attribute_string ( const std::string attribute,
const Glib::ustring value,
FileQueryInfoFlags  flags 
)

A set_attribute_string() convenience overload.

bool Gio::File::set_attribute_uint32 ( const std::string attribute,
guint32  value,
FileQueryInfoFlags  flags,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Sets attribute of type G_FILE_ATTRIBUTE_TYPE_UINT32 to value.

If attribute is of a different type, this operation will fail.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
attributeA string containing the attribute's name.
valueA #guint32 containing the attribute's new value.
flagsA FileQueryInfoFlags.
cancellableCancellable object.
Returns
true if the attribute was successfully set to value in the file, false otherwise.
Exceptions
Glib::Error
bool Gio::File::set_attribute_uint32 ( const std::string attribute,
guint32  value,
FileQueryInfoFlags  flags 
)

A set_attribute_uint32() convenience overload.

bool Gio::File::set_attribute_uint64 ( const std::string attribute,
guint64  value,
FileQueryInfoFlags  flags,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Sets attribute of type G_FILE_ATTRIBUTE_TYPE_UINT64 to value.

If attribute is of a different type, this operation will fail.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
attributeA string containing the attribute's name.
valueA #guint64 containing the attribute's new value.
flagsA FileQueryInfoFlags.
cancellableCancellable object.
Returns
true if the attribute was successfully set to value in the file, false otherwise.
Exceptions
Glib::Error
bool Gio::File::set_attribute_uint64 ( const std::string attribute,
guint64  value,
FileQueryInfoFlags  flags 
)

A set_attribute_uint64() convenience overload.

void Gio::File::set_attributes_async ( const Glib::RefPtr< FileInfo >&  info,
const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously sets the attributes of file with info.

For more details, see set_attributes_from_info() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call set_attributes_finish() to get the result of the operation.

Parameters
infoA FileInfo.
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
flagsA set of FileQueryInfoFlags.
io_priorityThe I/O priority of the request.
void Gio::File::set_attributes_async ( const Glib::RefPtr< FileInfo >&  info,
const SlotAsyncReady &  slot,
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously sets the attributes of file with info.

For more details, see set_attributes_from_info() which is the synchronous version of this call. When the operation is finished, slot will be called. You can then call set_attributes_finish() to get the result of the operation.

Parameters
infoA FileInfo.
slotA callback slot which will be called when the request is satisfied.
flagsA set of FileQueryInfoFlags.
io_priorityThe I/O priority of the request.
bool Gio::File::set_attributes_finish ( const Glib::RefPtr< AsyncResult >&  result,
const Glib::RefPtr< FileInfo >&  info 
)
bool Gio::File::set_attributes_from_info ( const Glib::RefPtr< FileInfo >&  info,
const Glib::RefPtr< Cancellable >&  cancellable,
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE 
)

Tries to set all attributes in the FileInfo on the target values, not stopping on the first error.

If there is any error during this operation then a Gio::Error will be thrown. Error on particular fields are flagged by setting the "status" field in the attribute value to FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can also detect further errors.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
infoA FileInfo.
cancellableA Cancellable object which can be used to cancel the operation.
flagsA set of FileQueryInfoFlags.
Returns
true if there was any error, false otherwise.
bool Gio::File::set_attributes_from_info ( const Glib::RefPtr< FileInfo >&  info,
FileQueryInfoFlags  flags = FileQueryInfoFlags::NONE 
)

Tries to set all attributes in the FileInfo on the target values, not stopping on the first error.

If there is any error during this operation then a Gio::Error will be thrown. Error on particular fields are flagged by setting the "status" field in the attribute value to FILE_ATTRIBUTE_STATUS_ERROR_SETTING, which means you can also detect further errors.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
infoA FileInfo.
flagsA set of FileQueryInfoFlags.
Returns
true if there was any error, false otherwise.
Glib::RefPtr<File> Gio::File::set_display_name ( const Glib::ustring display_name,
const Glib::RefPtr< Cancellable >&  cancellable 
)

Renames file to the specified display name.

The display name is converted from UTF8 to the correct encoding for the target filesystem if possible and the file is renamed to this.

If you want to implement a rename operation in the user interface the edit name (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.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
display_nameA string.
cancellableCancellable object.
Returns
A File specifying what file was renamed to, or nullptr if there was an error.
Exceptions
Glib::Error
Glib::RefPtr<File> Gio::File::set_display_name ( const Glib::ustring display_name)

A set_display_name() convenience overload.

void Gio::File::set_display_name_async ( const Glib::ustring display_name,
const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously sets the display name for a given Gio::File.

For the synchronous version of this function, see set_display_name(). When the operation is finished, slot will be called. You can then call set_display_name_finish() to get the result of the operation.

Parameters
display_nameA string.
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
io_priorityThe I/O priority of the request.
void Gio::File::set_display_name_async ( const Glib::ustring display_name,
const SlotAsyncReady &  slot,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously sets the display name for a given Gio::File.

For the synchronous version of this function, see set_display_name(). When the operation is finished, slot will be called. You can then call set_display_name_finish() to get the result of the operation.

Parameters
display_nameA string.
slotA callback slot which will be called when the request is satisfied.
io_priorityThe I/O priority of the request.
Glib::RefPtr<File> Gio::File::set_display_name_finish ( const Glib::RefPtr< AsyncResult >&  res)

Finishes setting a display name started with g_file_set_display_name_async().

Parameters
resA AsyncResult.
Returns
A File or nullptr on error. Free the returned object with Glib::object_unref().
Exceptions
Glib::Error
void Gio::File::start_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const Glib::RefPtr< MountOperation >&  start_operation,
Drive::StartFlags  flags = Drive::StartFlags::NONE 
)

Starts a file of type Mountable.

Using start_operation, you can request callbacks when, for instance, passwords are needed during authentication.

When this operation has completed, slot will be called and the operation can be finalized with start_mountable_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
slotA callback to call when the request is satisfied.
cancellableA Cancellable object.
start_operationA MountOperation, or nullptr to avoid user interaction.
flagsFlags affecting the operation
Since glibmm 2.24:
void Gio::File::start_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< MountOperation >&  start_operation,
Drive::StartFlags  flags = Drive::StartFlags::NONE 
)

Starts a file of type Mountable.

Using start_operation, you can request callbacks when, for instance, passwords are needed during authentication.

When this operation has completed, slot will be called and the operation can be finalized with start_mountable_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
slotA callback to call when the request is satisfied.
start_operationA MountOperation, or nullptr to avoid user interaction.
flagsFlags affecting the operation
Since glibmm 2.24:
bool Gio::File::start_mountable_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes a start operation.

See g_file_start_mountable() for details.

Finish an asynchronous start operation that was started with g_file_start_mountable().

Since glibmm 2.22:
Parameters
resultA AsyncResult.
Returns
true if the operation finished successfully. false otherwise.
Exceptions
Glib::Error
void Gio::File::stop_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const Glib::RefPtr< MountOperation >&  start_operation,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Stops a file of type Mountable.

Using start_operation, you can request callbacks when, for instance, passwords are needed during authentication.

When this operation has completed, slot will be called and the operation can be finalized with stop_mountable_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
slotA callback to call when the request is satisfied.
cancellableA Cancellable object.
start_operationA MountOperation, or nullptr to avoid user interaction.
flagsFlags affecting the operation
Since glibmm 2.24:
void Gio::File::stop_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< MountOperation >&  start_operation,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Stops a file of type Mountable.

Using start_operation, you can request callbacks when, for instance, passwords are needed during authentication.

When this operation has completed, slot will be called and the operation can be finalized with stop_mountable_finish().

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters
slotA callback to call when the request is satisfied.
start_operationA MountOperation, or nullptr to avoid user interaction.
flagsFlags affecting the operation
Since glibmm 2.24:
bool Gio::File::stop_mountable_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes a stop operation, see g_file_stop_mountable() for details.

Finish an asynchronous stop operation that was started with g_file_stop_mountable().

Since glibmm 2.22:
Parameters
resultA AsyncResult.
Returns
true if the operation finished successfully. false otherwise.
Exceptions
Glib::Error
bool Gio::File::supports_thread_contexts ( ) const

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.

Since glibmm 2.22:
Returns
Whether or not file supports thread-default contexts.
bool Gio::File::trash ( const Glib::RefPtr< Cancellable >&  cancellable)

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 throw a Gio::Error with NOT_SUPPORTED.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters
cancellableCancellable object.
Returns
true on successful trash, false otherwise.
Exceptions
Glib::Error
bool Gio::File::trash ( )

A trash() convenience overload.

void Gio::File::trash_async ( const SlotAsyncReady &  slot_ready,
const Glib::RefPtr< Cancellable >&  cancellable,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously sends the file to the Trash location, if possible.

Parameters
slot_readyA SlotAsyncReady to call when the request is satisfied
cancellableA Cancellable object which can be used to cancel the operation
io_priorityThe I/O priority of the request
Since glibmm 2.38:
void Gio::File::trash_async ( const SlotAsyncReady &  slot_ready,
int  io_priority = Glib::PRIORITY_DEFAULT 
)

Asynchronously sends the file to the Trash location, if possible.

Parameters
slot_readyA SlotAsyncReady to call when the request is satisfied
io_priorityThe I/O priority of the request
Since glibmm 2.38:
bool Gio::File::trash_finish ( const Glib::RefPtr< AsyncResult >&  result)

Finishes an asynchronous file trashing operation, started with g_file_trash_async().

Virtual: trash_finish

Since glibmm 2.38:
Parameters
resultA AsyncResult.
Returns
true on successful trash, false otherwise.
Exceptions
Glib::Error
void Gio::File::unmount_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Unmounts a file of type FILE_TYPE_MOUNTABLE.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

When the operation is finished, slot will be called. You can then call unmount_mountable_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
flagsFlags affecting the operation.
void Gio::File::unmount_mountable ( const SlotAsyncReady &  slot,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Unmounts a file of type FILE_TYPE_MOUNTABLE.

When the operation is finished, slot will be called. You can then call unmount_mountable_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
flagsFlags affecting the operation.
void Gio::File::unmount_mountable ( Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE)

Unmounts a file of type FILE_TYPE_MOUNTABLE.

Parameters
flagsFlags affecting the operation.
void Gio::File::unmount_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable >&  cancellable,
const Glib::RefPtr< MountOperation >&  mount_operation,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Unmounts a file of type FILE_TYPE_MOUNTABLE.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

When the operation is finished, slot will be called. You can then call unmount_mountable_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
cancellableA Cancellable object which can be used to cancel the operation.
mount_operationA MountOperation
flagsFlags affecting the operation.
Since glibmm 2.24:
void Gio::File::unmount_mountable ( const SlotAsyncReady &  slot,
const Glib::RefPtr< MountOperation >&  mount_operation,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Unmounts a file of type FILE_TYPE_MOUNTABLE.

When the operation is finished, slot will be called. You can then call unmount_mountable_finish() to get the result of the operation.

Parameters
slotA callback slot which will be called when the request is satisfied.
mount_operationA MountOperation
flagsFlags affecting the operation.
Since glibmm 2.24:
void Gio::File::unmount_mountable ( const Glib::RefPtr< MountOperation >&  mount_operation,
Mount::UnmountFlags  flags = Mount::UnmountFlags::NONE 
)

Unmounts a file of type FILE_TYPE_MOUNTABLE.

Parameters
mount_operationA MountOperation
flagsFlags affecting the operation.
Since glibmm 2.24:
bool Gio::File::unmount_mountable_finish ( const Glib::RefPtr< AsyncResult >&  result)

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().

Since glibmm 2.22:
Parameters
resultA AsyncResult.
Returns
true if the operation finished successfully. false otherwise.
Exceptions
Glib::Error

Friends And Related Function Documentation

Glib::RefPtr< Gio::File > wrap ( GFile *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.