Gio.FileInfo¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
Virtual Methods¶
- Inherited:
Properties¶
None
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class Gio.FileInfo(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
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 aGFileInfo
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 aGFile
.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 aGFileInfo
.[struct`Gio`.FileAttributeMatcher] allows for searching through a
GFileInfo
for attributes.- classmethod new()[source]¶
- Returns:
a
Gio.FileInfo
.- Return type:
Creates a new file info structure.
- 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:
Duplicates a file info structure.
- get_access_date_time()[source]¶
- Returns:
access time, or
None
if unknown- Return type:
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 containGio.FILE_ATTRIBUTE_TIME_ACCESS
. IfGio.FILE_ATTRIBUTE_TIME_ACCESS_USEC
is provided, the resultingGLib.DateTime
will additionally have microsecond precision.If nanosecond precision is needed,
Gio.FILE_ATTRIBUTE_TIME_ACCESS_NSEC
must be queried separately usingGio.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 withGLib.free
().- Return type:
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:
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:
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.- 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:
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:
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:
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, orNone
otherwise.- Return type:
Gets the value of a
GObject.Object
attribute. If the attribute does not contain aGObject.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, orGio.FileAttributeStatus.UNSET
if the key is invalid.- Return type:
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:
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:
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, orGio.FileAttributeType.INVALID
if the key is not set.- Return type:
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:
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:
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]¶
-
Gets the file’s content type.
It is an error to call this if the
Gio.FileInfo
does not containGio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
.
- get_creation_date_time()[source]¶
- Returns:
creation time, or
None
if unknown- Return type:
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 containGio.FILE_ATTRIBUTE_TIME_CREATED
. IfGio.FILE_ATTRIBUTE_TIME_CREATED_USEC
is provided, the resultingGLib.DateTime
will additionally have microsecond precision.If nanosecond precision is needed,
Gio.FILE_ATTRIBUTE_TIME_CREATED_NSEC
must be queried separately usingGio.FileInfo.get_attribute_uint32
().New in version 2.70.
- get_deletion_date()[source]¶
- Returns:
a
GLib.DateTime
, orNone
.- Return type:
Returns the
GLib.DateTime
representing the deletion date of the file, as available inGio.FILE_ATTRIBUTE_TRASH_DELETION_DATE
. If theGio.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:
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 containGio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
.
- get_edit_name()[source]¶
- Returns:
a string containing the edit name.
- Return type:
Gets the edit name for a file.
It is an error to call this if the
Gio.FileInfo
does not containGio.FILE_ATTRIBUTE_STANDARD_EDIT_NAME
.
- get_etag()[source]¶
-
Gets the entity tag for a given
Gio.FileInfo
. SeeGio.FILE_ATTRIBUTE_ETAG_VALUE
.It is an error to call this if the
Gio.FileInfo
does not containGio.FILE_ATTRIBUTE_ETAG_VALUE
.
- get_file_type()[source]¶
- Returns:
a
Gio.FileType
for the given file.- Return type:
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 containGio.FILE_ATTRIBUTE_STANDARD_TYPE
.
- get_icon()[source]¶
-
Gets the icon for a file.
It is an error to call this if the
Gio.FileInfo
does not containGio.FILE_ATTRIBUTE_STANDARD_ICON
.
- get_is_backup()[source]¶
-
Checks if a file is a backup file.
It is an error to call this if the
Gio.FileInfo
does not containGio.FILE_ATTRIBUTE_STANDARD_IS_BACKUP
.
-
Checks if a file is hidden.
It is an error to call this if the
Gio.FileInfo
does not containGio.FILE_ATTRIBUTE_STANDARD_IS_HIDDEN
.
- get_is_symlink()[source]¶
-
Checks if a file is a symlink.
It is an error to call this if the
Gio.FileInfo
does not containGio.FILE_ATTRIBUTE_STANDARD_IS_SYMLINK
.
- get_modification_date_time()[source]¶
- Returns:
modification time, or
None
if unknown- Return type:
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 containGio.FILE_ATTRIBUTE_TIME_MODIFIED
. IfGio.FILE_ATTRIBUTE_TIME_MODIFIED_USEC
is provided, the resultingGLib.DateTime
will additionally have microsecond precision.If nanosecond precision is needed,
Gio.FILE_ATTRIBUTE_TIME_MODIFIED_NSEC
must be queried separately usingGio.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 containGio.FILE_ATTRIBUTE_TIME_MODIFIED
. IfGio.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, asGLib.TimeVal
is deprecated due to the year 2038 problem.
- get_name()[source]¶
- Returns:
a string containing the file name.
- Return type:
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 containGio.FILE_ATTRIBUTE_STANDARD_NAME
.
- get_size()[source]¶
- Returns:
a #goffset containing the file’s size (in bytes).
- Return type:
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 containGio.FILE_ATTRIBUTE_STANDARD_SIZE
.
- get_sort_order()[source]¶
- Returns:
a #gint32 containing the value of the “standard::sort_order” attribute.
- Return type:
Gets the value of the sort_order attribute from the
Gio.FileInfo
. SeeGio.FILE_ATTRIBUTE_STANDARD_SORT_ORDER
.It is an error to call this if the
Gio.FileInfo
does not containGio.FILE_ATTRIBUTE_STANDARD_SORT_ORDER
.
- get_symbolic_icon()[source]¶
-
Gets the symbolic icon for a file.
It is an error to call this if the
Gio.FileInfo
does not containGio.FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON
.New in version 2.34.
- get_symlink_target()[source]¶
-
Gets the symlink target for a given
Gio.FileInfo
.It is an error to call this if the
Gio.FileInfo
does not containGio.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:
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:
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
orNone
) – a file attribute key’s namespace, orNone
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:
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
) – aGLib.DateTime
.
Sets the
Gio.FILE_ATTRIBUTE_TIME_ACCESS
andGio.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:
attribute (
str
) – a file attribute key.type (
Gio.FileAttributeType
) – aGio.FileAttributeType
value_p (
object
) – pointer to the value
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]¶
-
Sets the attribute to contain the given attr_value, if possible.
- set_attribute_byte_string(attribute, attr_value)[source]¶
-
Sets the attribute to contain the given attr_value, if possible.
- set_attribute_file_path(attribute, attr_value)[source]¶
-
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]¶
-
Sets the attribute to contain the given attr_value, if possible.
- set_attribute_int64(attribute, attr_value)[source]¶
- Parameters:
Sets the attribute to contain the given attr_value, if possible.
- set_attribute_mask(mask)[source]¶
- Parameters:
mask (
Gio.FileAttributeMatcher
) – aGio.FileAttributeMatcher
.
Sets mask on self to match specific attribute types.
- set_attribute_object(attribute, attr_value)[source]¶
- Parameters:
attribute (
str
) – a file attribute key.attr_value (
GObject.Object
) – aGObject.Object
.
Sets the attribute to contain the given attr_value, if possible.
- set_attribute_status(attribute, status)[source]¶
- Parameters:
attribute (
str
) – a file attribute keystatus (
Gio.FileAttributeStatus
) – aGio.FileAttributeStatus
- Returns:
True
if the status was changed,False
if the key was not set.- Return type:
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]¶
-
Sets the attribute to contain the given attr_value, if possible.
- set_attribute_stringv(attribute, attr_value)[source]¶
- Parameters:
Sets the attribute to contain the given attr_value, if possible.
Sinze: 2.22
- set_attribute_uint32(attribute, attr_value)[source]¶
-
Sets the attribute to contain the given attr_value, if possible.
- set_attribute_uint64(attribute, attr_value)[source]¶
-
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
. SeeGio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
.
- set_creation_date_time(creation_time)[source]¶
- Parameters:
creation_time (
GLib.DateTime
) – aGLib.DateTime
.
Sets the
Gio.FILE_ATTRIBUTE_TIME_CREATED
andGio.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
. SeeGio.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
) – aGio.FileType
.
Sets the file type in a
Gio.FileInfo
to type. SeeGio.FILE_ATTRIBUTE_STANDARD_TYPE
.
- set_icon(icon)[source]¶
-
Sets the icon for a given
Gio.FileInfo
. SeeGio.FILE_ATTRIBUTE_STANDARD_ICON
.
-
Sets the “is_hidden” attribute in a
Gio.FileInfo
according to is_hidden. SeeGio.FILE_ATTRIBUTE_STANDARD_IS_HIDDEN
.
- set_is_symlink(is_symlink)[source]¶
-
Sets the “is_symlink” attribute in a
Gio.FileInfo
according to is_symlink. SeeGio.FILE_ATTRIBUTE_STANDARD_IS_SYMLINK
.
- set_modification_date_time(mtime)[source]¶
- Parameters:
mtime (
GLib.DateTime
) – aGLib.DateTime
.
Sets the
Gio.FILE_ATTRIBUTE_TIME_MODIFIED
andGio.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
) – aGLib.TimeVal
.
Sets the
Gio.FILE_ATTRIBUTE_TIME_MODIFIED
andGio.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, asGLib.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
. SeeGio.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]¶
-
Sets the symbolic icon for a given
Gio.FileInfo
. SeeGio.FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON
.New in version 2.34.
- set_symlink_target(symlink_target)[source]¶
- 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.