Gio.FileInfo

g GObject.Object GObject.Object Gio.FileInfo Gio.FileInfo GObject.Object->Gio.FileInfo

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new ()

clear_status ()

copy_into (dest_info)

dup ()

get_access_date_time ()

get_attribute_as_string (attribute)

get_attribute_boolean (attribute)

get_attribute_byte_string (attribute)

get_attribute_data (attribute)

get_attribute_file_path (attribute)

get_attribute_int32 (attribute)

get_attribute_int64 (attribute)

get_attribute_object (attribute)

get_attribute_status (attribute)

get_attribute_string (attribute)

get_attribute_stringv (attribute)

get_attribute_type (attribute)

get_attribute_uint32 (attribute)

get_attribute_uint64 (attribute)

get_content_type ()

get_creation_date_time ()

get_deletion_date ()

get_display_name ()

get_edit_name ()

get_etag ()

get_file_type ()

get_icon ()

get_is_backup ()

get_is_hidden ()

get_is_symlink ()

get_modification_date_time ()

get_modification_time ()

get_name ()

get_size ()

get_sort_order ()

get_symbolic_icon ()

get_symlink_target ()

has_attribute (attribute)

has_namespace (name_space)

list_attributes (name_space)

remove_attribute (attribute)

set_access_date_time (atime)

set_attribute (attribute, type, value_p)

set_attribute_boolean (attribute, attr_value)

set_attribute_byte_string (attribute, attr_value)

set_attribute_file_path (attribute, attr_value)

set_attribute_int32 (attribute, attr_value)

set_attribute_int64 (attribute, attr_value)

set_attribute_mask (mask)

set_attribute_object (attribute, attr_value)

set_attribute_status (attribute, status)

set_attribute_string (attribute, attr_value)

set_attribute_stringv (attribute, attr_value)

set_attribute_uint32 (attribute, attr_value)

set_attribute_uint64 (attribute, attr_value)

set_content_type (content_type)

set_creation_date_time (creation_time)

set_display_name (display_name)

set_edit_name (edit_name)

set_file_type (type)

set_icon (icon)

set_is_hidden (is_hidden)

set_is_symlink (is_symlink)

set_modification_date_time (mtime)

set_modification_time (mtime)

set_name (name)

set_size (size)

set_sort_order (sort_order)

set_symbolic_icon (icon)

set_symlink_target (symlink_target)

unset_attribute_mask ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Gio.FileInfo(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Gio.FileInfoClass

Stores information about a file system object referenced by a [iface`Gio`.File].

Functionality for manipulating basic metadata for files. GFileInfo implements methods for getting information that all files should contain, and allows for manipulation of extended attributes.

See file-attributes.html for more information on how GIO handles file attributes.

To obtain a GFileInfo for a [iface`Gio`.File], use [method`Gio`.File.query_info] (or its async variant). To obtain a GFileInfo for a file input or output stream, use [method`Gio`.FileInputStream.query_info] or [method`Gio`.FileOutputStream.query_info] (or their async variants).

To change the actual attributes of a file, you should then set the attribute in the GFileInfo and call [method`Gio`.File.set_attributes_from_info] or [method`Gio`.File.set_attributes_async] on a GFile.

However, not all attributes can be changed in the file. For instance, the actual size of a file cannot be changed via [method`Gio`.FileInfo.set_size]. You may call [method`Gio`.File.query_settable_attributes] and [method`Gio`.File.query_writable_namespaces] to discover the settable attributes of a particular file at runtime.

The direct accessors, such as [method`Gio`.FileInfo.get_name], are slightly more optimized than the generic attribute accessors, such as [method`Gio`.FileInfo.get_attribute_byte_string].This optimization will matter only if calling the API in a tight loop.

It is an error to call these accessors without specifying their required file attributes when creating the GFileInfo. Use [method`Gio`.FileInfo.has_attribute] or [method`Gio`.FileInfo.list_attributes] to check what attributes are specified for a GFileInfo.

[struct`Gio`.FileAttributeMatcher] allows for searching through a GFileInfo for attributes.

classmethod new()[source]
Returns:

a Gio.FileInfo.

Return type:

Gio.FileInfo

Creates a new file info structure.

clear_status()[source]

Clears the status information from self.

copy_into(dest_info)[source]
Parameters:

dest_info (Gio.FileInfo) – destination to copy attributes to.

First clears all of the GFileAttribute of dest_info, and then copies all of the file attributes from self to dest_info.

dup()[source]
Returns:

a duplicate Gio.FileInfo of self.

Return type:

Gio.FileInfo

Duplicates a file info structure.

get_access_date_time()[source]
Returns:

access time, or None if unknown

Return type:

GLib.DateTime or None

Gets the access time of the current self and returns it as a GLib.DateTime.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_TIME_ACCESS. If Gio.FILE_ATTRIBUTE_TIME_ACCESS_USEC is provided, the resulting GLib.DateTime will additionally have microsecond precision.

If nanosecond precision is needed, Gio.FILE_ATTRIBUTE_TIME_ACCESS_NSEC must be queried separately using Gio.FileInfo.get_attribute_uint32().

New in version 2.70.

get_attribute_as_string(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

a UTF-8 string associated with the given attribute, or None if the attribute wasn’t set. When you’re done with the string it must be freed with GLib.free().

Return type:

str or None

Gets the value of an attribute, formatted as a string. This escapes things as needed to make the string valid UTF-8.

get_attribute_boolean(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

the boolean value contained within the attribute.

Return type:

bool

Gets the value of a boolean attribute. If the attribute does not contain a boolean value, False will be returned.

get_attribute_byte_string(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

the contents of the attribute value as a byte string, or None otherwise.

Return type:

str or None

Gets the value of a byte string attribute. If the attribute does not contain a byte string, None will be returned.

get_attribute_data(attribute)[source]
Parameters:

attribute (str) – a file attribute key

Returns:

True if self has an attribute named attribute, False otherwise.

type:

return location for the attribute type, or None

value_pp:

return location for the attribute value, or None; the attribute value will not be None

status:

return location for the attribute status, or None

Return type:

(bool, type: Gio.FileAttributeType, value_pp: object, status: Gio.FileAttributeStatus)

Gets the attribute type, value and status for an attribute key.

get_attribute_file_path(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

the contents of the attribute value as a file path, or None otherwise.

Return type:

str or None

Gets the value of a byte string attribute as a file path.

If the attribute does not contain a byte string, NULL will be returned.

This function is meant to be used by language bindings that have specific handling for Unix paths.

New in version 2.78.

get_attribute_int32(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

a signed 32-bit integer from the attribute.

Return type:

int

Gets a signed 32-bit integer contained within the attribute. If the attribute does not contain a signed 32-bit integer, or is invalid, 0 will be returned.

get_attribute_int64(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

a signed 64-bit integer from the attribute.

Return type:

int

Gets a signed 64-bit integer contained within the attribute. If the attribute does not contain a signed 64-bit integer, or is invalid, 0 will be returned.

get_attribute_object(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

a GObject.Object associated with the given attribute, or None otherwise.

Return type:

GObject.Object or None

Gets the value of a GObject.Object attribute. If the attribute does not contain a GObject.Object, None will be returned.

get_attribute_status(attribute)[source]
Parameters:

attribute (str) – a file attribute key

Returns:

a Gio.FileAttributeStatus for the given attribute, or Gio.FileAttributeStatus.UNSET if the key is invalid.

Return type:

Gio.FileAttributeStatus

Gets the attribute status for an attribute key.

get_attribute_string(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

the contents of the attribute value as a UTF-8 string, or None otherwise.

Return type:

str or None

Gets the value of a string attribute. If the attribute does not contain a string, None will be returned.

get_attribute_stringv(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

the contents of the attribute value as a stringv, or None otherwise. Do not free. These returned strings are UTF-8.

Return type:

[str] or None

Gets the value of a stringv attribute. If the attribute does not contain a stringv, None will be returned.

New in version 2.22.

get_attribute_type(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

a Gio.FileAttributeType for the given attribute, or Gio.FileAttributeType.INVALID if the key is not set.

Return type:

Gio.FileAttributeType

Gets the attribute type for an attribute key.

get_attribute_uint32(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

an unsigned 32-bit integer from the attribute.

Return type:

int

Gets an unsigned 32-bit integer contained within the attribute. If the attribute does not contain an unsigned 32-bit integer, or is invalid, 0 will be returned.

get_attribute_uint64(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

a unsigned 64-bit integer from the attribute.

Return type:

int

Gets a unsigned 64-bit integer contained within the attribute. If the attribute does not contain an unsigned 64-bit integer, or is invalid, 0 will be returned.

get_content_type()[source]
Returns:

a string containing the file’s content type, or None if unknown.

Return type:

str or None

Gets the file’s content type.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.

get_creation_date_time()[source]
Returns:

creation time, or None if unknown

Return type:

GLib.DateTime or None

Gets the creation time of the current self and returns it as a GLib.DateTime.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_TIME_CREATED. If Gio.FILE_ATTRIBUTE_TIME_CREATED_USEC is provided, the resulting GLib.DateTime will additionally have microsecond precision.

If nanosecond precision is needed, Gio.FILE_ATTRIBUTE_TIME_CREATED_NSEC must be queried separately using Gio.FileInfo.get_attribute_uint32().

New in version 2.70.

get_deletion_date()[source]
Returns:

a GLib.DateTime, or None.

Return type:

GLib.DateTime or None

Returns the GLib.DateTime representing the deletion date of the file, as available in Gio.FILE_ATTRIBUTE_TRASH_DELETION_DATE. If the Gio.FILE_ATTRIBUTE_TRASH_DELETION_DATE attribute is unset, None is returned.

New in version 2.36.

get_display_name()[source]
Returns:

a string containing the display name.

Return type:

str

Gets a display name for a file. This is guaranteed to always be set.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.

get_edit_name()[source]
Returns:

a string containing the edit name.

Return type:

str

Gets the edit name for a file.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_EDIT_NAME.

get_etag()[source]
Returns:

a string containing the value of the “etag:value” attribute.

Return type:

str or None

Gets the entity tag for a given Gio.FileInfo. See Gio.FILE_ATTRIBUTE_ETAG_VALUE.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_ETAG_VALUE.

get_file_type()[source]
Returns:

a Gio.FileType for the given file.

Return type:

Gio.FileType

Gets a file’s type (whether it is a regular file, symlink, etc). This is different from the file’s content type, see Gio.FileInfo.get_content_type().

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_TYPE.

get_icon()[source]
Returns:

Gio.Icon for the given self.

Return type:

Gio.Icon or None

Gets the icon for a file.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_ICON.

get_is_backup()[source]
Returns:

True if file is a backup file, False otherwise.

Return type:

bool

Checks if a file is a backup file.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_IS_BACKUP.

get_is_hidden()[source]
Returns:

True if the file is a hidden file, False otherwise.

Return type:

bool

Checks if a file is hidden.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.

Returns:

True if the given self is a symlink.

Return type:

bool

Checks if a file is a symlink.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.

get_modification_date_time()[source]
Returns:

modification time, or None if unknown

Return type:

GLib.DateTime or None

Gets the modification time of the current self and returns it as a GLib.DateTime.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_TIME_MODIFIED. If Gio.FILE_ATTRIBUTE_TIME_MODIFIED_USEC is provided, the resulting GLib.DateTime will additionally have microsecond precision.

If nanosecond precision is needed, Gio.FILE_ATTRIBUTE_TIME_MODIFIED_NSEC must be queried separately using Gio.FileInfo.get_attribute_uint32().

New in version 2.62.

get_modification_time()[source]
Returns:

a GLib.TimeVal.

Return type:

result: GLib.TimeVal

Gets the modification time of the current self and sets it in result.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_TIME_MODIFIED. If Gio.FILE_ATTRIBUTE_TIME_MODIFIED_USEC is provided it will be used too.

Deprecated since version 2.62: Use Gio.FileInfo.get_modification_date_time() instead, as GLib.TimeVal is deprecated due to the year 2038 problem.

get_name()[source]
Returns:

a string containing the file name.

Return type:

str

Gets the name for a file. This is guaranteed to always be set.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_NAME.

get_size()[source]
Returns:

a #goffset containing the file’s size (in bytes).

Return type:

int

Gets the file’s size (in bytes). The size is retrieved through the value of the Gio.FILE_ATTRIBUTE_STANDARD_SIZE attribute and is converted from #guint64 to #goffset before returning the result.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_SIZE.

get_sort_order()[source]
Returns:

a #gint32 containing the value of the “standard::sort_order” attribute.

Return type:

int

Gets the value of the sort_order attribute from the Gio.FileInfo. See Gio.FILE_ATTRIBUTE_STANDARD_SORT_ORDER.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_SORT_ORDER.

get_symbolic_icon()[source]
Returns:

Gio.Icon for the given self.

Return type:

Gio.Icon or None

Gets the symbolic icon for a file.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON.

New in version 2.34.

Returns:

a string containing the symlink target.

Return type:

str or None

Gets the symlink target for a given Gio.FileInfo.

It is an error to call this if the Gio.FileInfo does not contain Gio.FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET.

has_attribute(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Returns:

True if self has an attribute named attribute, False otherwise.

Return type:

bool

Checks if a file info structure has an attribute named attribute.

has_namespace(name_space)[source]
Parameters:

name_space (str) – a file attribute namespace.

Returns:

True if self has an attribute in name_space, False otherwise.

Return type:

bool

Checks if a file info structure has an attribute in the specified name_space.

New in version 2.22.

list_attributes(name_space)[source]
Parameters:

name_space (str or None) – a file attribute key’s namespace, or None to list all attributes.

Returns:

a null-terminated array of strings of all of the possible attribute types for the given name_space, or None on error.

Return type:

[str] or None

Lists the file info structure’s attributes.

remove_attribute(attribute)[source]
Parameters:

attribute (str) – a file attribute key.

Removes all cases of attribute from self if it exists.

set_access_date_time(atime)[source]
Parameters:

atime (GLib.DateTime) – a GLib.DateTime.

Sets the Gio.FILE_ATTRIBUTE_TIME_ACCESS and Gio.FILE_ATTRIBUTE_TIME_ACCESS_USEC attributes in the file info to the given date/time value.

Gio.FILE_ATTRIBUTE_TIME_ACCESS_NSEC will be cleared.

New in version 2.70.

set_attribute(attribute, type, value_p)[source]
Parameters:

Sets the attribute to contain the given value, if possible. To unset the attribute, use Gio.FileAttributeType.INVALID for type.

set_attribute_boolean(attribute, attr_value)[source]
Parameters:
  • attribute (str) – a file attribute key.

  • attr_value (bool) – a boolean value.

Sets the attribute to contain the given attr_value, if possible.

set_attribute_byte_string(attribute, attr_value)[source]
Parameters:
  • attribute (str) – a file attribute key.

  • attr_value (str) – a byte string.

Sets the attribute to contain the given attr_value, if possible.

set_attribute_file_path(attribute, attr_value)[source]
Parameters:
  • attribute (str) – a file attribute key.

  • attr_value (str) – a file path.

Sets the attribute to contain the given attr_value, if possible.

This function is meant to be used by language bindings that have specific handling for Unix paths.

New in version 2.78.

set_attribute_int32(attribute, attr_value)[source]
Parameters:
  • attribute (str) – a file attribute key.

  • attr_value (int) – a signed 32-bit integer

Sets the attribute to contain the given attr_value, if possible.

set_attribute_int64(attribute, attr_value)[source]
Parameters:
  • attribute (str) – attribute name to set.

  • attr_value (int) – int64 value to set attribute to.

Sets the attribute to contain the given attr_value, if possible.

set_attribute_mask(mask)[source]
Parameters:

mask (Gio.FileAttributeMatcher) – a Gio.FileAttributeMatcher.

Sets mask on self to match specific attribute types.

set_attribute_object(attribute, attr_value)[source]
Parameters:

Sets the attribute to contain the given attr_value, if possible.

set_attribute_status(attribute, status)[source]
Parameters:
Returns:

True if the status was changed, False if the key was not set.

Return type:

bool

Sets the attribute status for an attribute key. This is only needed by external code that implement Gio.File.set_attributes_from_info() or similar functions.

The attribute must exist in self for this to work. Otherwise False is returned and self is unchanged.

New in version 2.22.

set_attribute_string(attribute, attr_value)[source]
Parameters:
  • attribute (str) – a file attribute key.

  • attr_value (str) – a UTF-8 string.

Sets the attribute to contain the given attr_value, if possible.

set_attribute_stringv(attribute, attr_value)[source]
Parameters:
  • attribute (str) – a file attribute key

  • attr_value ([str]) – a None terminated array of UTF-8 strings.

Sets the attribute to contain the given attr_value, if possible.

Sinze: 2.22

set_attribute_uint32(attribute, attr_value)[source]
Parameters:
  • attribute (str) – a file attribute key.

  • attr_value (int) – an unsigned 32-bit integer.

Sets the attribute to contain the given attr_value, if possible.

set_attribute_uint64(attribute, attr_value)[source]
Parameters:
  • attribute (str) – a file attribute key.

  • attr_value (int) – an unsigned 64-bit integer.

Sets the attribute to contain the given attr_value, if possible.

set_content_type(content_type)[source]
Parameters:

content_type (str) – a content type. See GContentType

Sets the content type attribute for a given Gio.FileInfo. See Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.

set_creation_date_time(creation_time)[source]
Parameters:

creation_time (GLib.DateTime) – a GLib.DateTime.

Sets the Gio.FILE_ATTRIBUTE_TIME_CREATED and Gio.FILE_ATTRIBUTE_TIME_CREATED_USEC attributes in the file info to the given date/time value.

Gio.FILE_ATTRIBUTE_TIME_CREATED_NSEC will be cleared.

New in version 2.70.

set_display_name(display_name)[source]
Parameters:

display_name (str) – a string containing a display name.

Sets the display name for the current Gio.FileInfo. See Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.

set_edit_name(edit_name)[source]
Parameters:

edit_name (str) – a string containing an edit name.

Sets the edit name for the current file. See Gio.FILE_ATTRIBUTE_STANDARD_EDIT_NAME.

set_file_type(type)[source]
Parameters:

type (Gio.FileType) – a Gio.FileType.

Sets the file type in a Gio.FileInfo to type. See Gio.FILE_ATTRIBUTE_STANDARD_TYPE.

set_icon(icon)[source]
Parameters:

icon (Gio.Icon) – a Gio.Icon.

Sets the icon for a given Gio.FileInfo. See Gio.FILE_ATTRIBUTE_STANDARD_ICON.

set_is_hidden(is_hidden)[source]
Parameters:

is_hidden (bool) – a bool.

Sets the “is_hidden” attribute in a Gio.FileInfo according to is_hidden. See Gio.FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.

Parameters:

is_symlink (bool) – a bool.

Sets the “is_symlink” attribute in a Gio.FileInfo according to is_symlink. See Gio.FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.

set_modification_date_time(mtime)[source]
Parameters:

mtime (GLib.DateTime) – a GLib.DateTime.

Sets the Gio.FILE_ATTRIBUTE_TIME_MODIFIED and Gio.FILE_ATTRIBUTE_TIME_MODIFIED_USEC attributes in the file info to the given date/time value.

Gio.FILE_ATTRIBUTE_TIME_MODIFIED_NSEC will be cleared.

New in version 2.62.

set_modification_time(mtime)[source]
Parameters:

mtime (GLib.TimeVal) – a GLib.TimeVal.

Sets the Gio.FILE_ATTRIBUTE_TIME_MODIFIED and Gio.FILE_ATTRIBUTE_TIME_MODIFIED_USEC attributes in the file info to the given time value.

Gio.FILE_ATTRIBUTE_TIME_MODIFIED_NSEC will be cleared.

Deprecated since version 2.62: Use Gio.FileInfo.set_modification_date_time() instead, as GLib.TimeVal is deprecated due to the year 2038 problem.

set_name(name)[source]
Parameters:

name (str) – a string containing a name.

Sets the name attribute for the current Gio.FileInfo. See Gio.FILE_ATTRIBUTE_STANDARD_NAME.

set_size(size)[source]
Parameters:

size (int) – a #goffset containing the file’s size.

Sets the Gio.FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info to the given size.

set_sort_order(sort_order)[source]
Parameters:

sort_order (int) – a sort order integer.

Sets the sort order attribute in the file info structure. See Gio.FILE_ATTRIBUTE_STANDARD_SORT_ORDER.

set_symbolic_icon(icon)[source]
Parameters:

icon (Gio.Icon) – a Gio.Icon.

Sets the symbolic icon for a given Gio.FileInfo. See Gio.FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON.

New in version 2.34.

Parameters:

symlink_target (str) – a static string containing a path to a symlink target.

Sets the Gio.FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info to the given symlink target.

unset_attribute_mask()[source]

Unsets a mask set by Gio.FileInfo.set_attribute_mask(), if one is set.