class Gio::FileInfo

Overview

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 [GFileAttribute][gio-GFileAttribute] for more information on how GIO handles file attributes.

To obtain a #GFileInfo for a #GFile, use g_file_query_info() (or its async variant). To obtain a #GFileInfo for a file input or output stream, use g_file_input_stream_query_info() or g_file_output_stream_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 g_file_set_attributes_from_info() or g_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 g_file_info_set_size(). You may call g_file_query_settable_attributes() and g_file_query_writable_namespaces() to discover the settable attributes of a particular file at runtime.

The direct accessors, such as g_file_info_get_name(), are slightly more optimized than the generic attribute accessors, such as g_file_info_get_attribute_byte_string().This optimization will matter only if calling the API in a tight loop.

#GFileAttributeMatcher allows for searching through a #GFileInfo for attributes.

Defined in:

lib/gi-crystal/src/auto/gio-2.0/file_info.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

==(other : self) ==, bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void) | Nil data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, hash(hasher) hash, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void) | Nil qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void) | Nil) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void) | Nil steal_data, steal_qdata(quark : UInt32) : Pointer(Void) | Nil steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

cast?(obj : GObject::Object) : self | Nil cast?, compat_control(what : UInt64, data : Pointer(Void) | Nil) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Macros inherited from class GObject::Object

previous_vfunc(*args) previous_vfunc, previous_vfunc!(*args) previous_vfunc!, signal(signature) signal

Constructor Detail

def self.new : self #

Creates a new file info structure.


[View source]

Class Method Detail

def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def access_date_time : GLib::DateTime | Nil #

Gets the access time of the current info and returns it as a #GDateTime.

This requires the %G_FILE_ATTRIBUTE_TIME_ACCESS attribute. If %G_FILE_ATTRIBUTE_TIME_ACCESS_USEC is provided, the resulting #GDateTime will have microsecond precision.


[View source]
def access_date_time=(atime : GLib::DateTime) : Nil #

Sets the %G_FILE_ATTRIBUTE_TIME_ACCESS and %G_FILE_ATTRIBUTE_TIME_ACCESS_USEC attributes in the file info to the given date/time value.


[View source]
def attribute_as_string(attribute : String) : String | Nil #

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


[View source]
def attribute_boolean(attribute : String) : Bool #

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


[View source]
def attribute_byte_string(attribute : String) : String | Nil #

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


[View source]
def attribute_data(attribute : String) : Bool #

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


[View source]
def attribute_int32(attribute : String) : Int32 #

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.


[View source]
def attribute_int64(attribute : String) : Int64 #

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.


[View source]
def attribute_mask=(mask : Gio::FileAttributeMatcher) : Nil #

Sets mask on info to match specific attribute types.


[View source]
def attribute_object(attribute : String) : GObject::Object | Nil #

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


[View source]
def attribute_status(attribute : String) : Gio::FileAttributeStatus #

Gets the attribute status for an attribute key.


[View source]
def attribute_string(attribute : String) : String | Nil #

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


[View source]
def attribute_stringv(attribute : String) : Enumerable(String) | Nil #

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


[View source]
def attribute_type(attribute : String) : Gio::FileAttributeType #

Gets the attribute type for an attribute key.


[View source]
def attribute_uint32(attribute : String) : UInt32 #

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.


[View source]
def attribute_uint64(attribute : String) : UInt64 #

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.


[View source]
def clear_status : Nil #

Clears the status information from info.


[View source]
def content_type : String | Nil #

Gets the file's content type.


[View source]
def content_type=(content_type : String) : Nil #

Sets the content type attribute for a given #GFileInfo. See %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.


[View source]
def copy_into(dest_info : Gio::FileInfo) : Nil #

First clears all of the [GFileAttribute][gio-GFileAttribute] of dest_info, and then copies all of the file attributes from src_info to dest_info.


[View source]
def creation_date_time : GLib::DateTime | Nil #

Gets the creation time of the current info and returns it as a #GDateTime.

This requires the %G_FILE_ATTRIBUTE_TIME_CREATED attribute. If %G_FILE_ATTRIBUTE_TIME_CREATED_USEC is provided, the resulting #GDateTime will have microsecond precision.


[View source]
def creation_date_time=(creation_time : GLib::DateTime) : Nil #

Sets the %G_FILE_ATTRIBUTE_TIME_CREATED and %G_FILE_ATTRIBUTE_TIME_CREATED_USEC attributes in the file info to the given date/time value.


[View source]
def deletion_date : GLib::DateTime | Nil #

Returns the #GDateTime representing the deletion date of the file, as available in G_FILE_ATTRIBUTE_TRASH_DELETION_DATE. If the G_FILE_ATTRIBUTE_TRASH_DELETION_DATE attribute is unset, nil is returned.


[View source]
def display_name : String #

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


[View source]
def display_name=(display_name : String) : Nil #

Sets the display name for the current #GFileInfo. See %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.


[View source]
def dup : Gio::FileInfo #

Duplicates a file info structure.


[View source]
def edit_name : String #

Gets the edit name for a file.


[View source]
def edit_name=(edit_name : String) : Nil #

Sets the edit name for the current file. See %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME.


[View source]
def etag : String | Nil #

Gets the [entity tag][gfile-etag] for a given #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.


[View source]
def file_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 g_file_info_get_content_type().


[View source]
def file_type=(type : Gio::FileType) : Nil #

Sets the file type in a #GFileInfo to type. See %G_FILE_ATTRIBUTE_STANDARD_TYPE.


[View source]
def has_attribute(attribute : String) : Bool #

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


[View source]
def has_namespace(name_space : String) : Bool #

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


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def icon : Gio::Icon | Nil #

Gets the icon for a file.


[View source]
def icon=(icon : Gio::Icon) : Nil #

Sets the icon for a given #GFileInfo. See %G_FILE_ATTRIBUTE_STANDARD_ICON.


[View source]
def is_backup : Bool #

Checks if a file is a backup file.


[View source]
def is_hidden : Bool #

Checks if a file is hidden.


[View source]
def is_hidden=(is_hidden : Bool) : Nil #

Sets the "is_hidden" attribute in a #GFileInfo according to is_hidden. See %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.


[View source]
def is_symlink : Bool #

Checks if a file is a symlink.


[View source]
def is_symlink=(is_symlink : Bool) : Nil #

Sets the "is_symlink" attribute in a #GFileInfo according to is_symlink. See %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.


[View source]
def list_attributes(name_space : String | Nil) : Enumerable(String) | Nil #

Lists the file info structure's attributes.


[View source]
def modification_date_time : GLib::DateTime | Nil #

Gets the modification time of the current info and returns it as a #GDateTime.

This requires the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute. If %G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC is provided, the resulting #GDateTime will have microsecond precision.


[View source]
def modification_date_time=(mtime : GLib::DateTime) : Nil #

Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED and %G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC attributes in the file info to the given date/time value.


[View source]
def modification_time : GLib::TimeVal #

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

DEPRECATED


[View source]
def modification_time=(mtime : GLib::TimeVal) : Nil #

Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED and %G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC attributes in the file info to the given time value.

DEPRECATED


[View source]
def name : Path #

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


[View source]
def name=(name : String) : Nil #

Sets the name attribute for the current #GFileInfo. See %G_FILE_ATTRIBUTE_STANDARD_NAME.


[View source]
def remove_attribute(attribute : String) : Nil #

Removes all cases of attribute from info if it exists.


[View source]
def set_attribute(attribute : String, type : Gio::FileAttributeType, value_p : Pointer(Void)) : Nil #

Sets the attribute to contain the given value, if possible. To unset the attribute, use %G_FILE_ATTRIBUTE_TYPE_INVALID for type.


[View source]
def set_attribute_boolean(attribute : String, attr_value : Bool) : Nil #

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


[View source]
def set_attribute_byte_string(attribute : String, attr_value : String) : Nil #

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


[View source]
def set_attribute_int32(attribute : String, attr_value : Int32) : Nil #

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


[View source]
def set_attribute_int64(attribute : String, attr_value : Int64) : Nil #

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


[View source]
def set_attribute_object(attribute : String, attr_value : GObject::Object) : Nil #

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


[View source]
def set_attribute_status(attribute : String, status : Gio::FileAttributeStatus) : Bool #

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

The attribute must exist in info for this to work. Otherwise false is returned and info is unchanged.


[View source]
def set_attribute_string(attribute : String, attr_value : String) : Nil #

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


[View source]
def set_attribute_stringv(attribute : String, attr_value : Enumerable(String)) : Nil #

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

Sinze: 2.22


[View source]
def set_attribute_uint32(attribute : String, attr_value : UInt32) : Nil #

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


[View source]
def set_attribute_uint64(attribute : String, attr_value : UInt64) : Nil #

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


[View source]
def size : Int64 #

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


[View source]
def size=(size : Int64) : Nil #

Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info to the given size.


[View source]
def sort_order : Int32 #

Gets the value of the sort_order attribute from the #GFileInfo. See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.


[View source]
def sort_order=(sort_order : Int32) : Nil #

Sets the sort order attribute in the file info structure. See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.


[View source]
def symbolic_icon : Gio::Icon | Nil #

Gets the symbolic icon for a file.


[View source]
def symbolic_icon=(icon : Gio::Icon) : Nil #

Sets the symbolic icon for a given #GFileInfo. See %G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON.


[View source]
def symlink_target : String | Nil #

Gets the symlink target for a given #GFileInfo.


[View source]
def symlink_target=(symlink_target : String) : Nil #

Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info to the given symlink target.


[View source]
def unset_attribute_mask : Nil #

Unsets a mask set by g_file_info_set_attribute_mask(), if one is set.


[View source]