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

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)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, 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)? qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? 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, 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

compat_control(what : UInt64, data : Pointer(Void)?) : 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

Constructor Detail

def self.new : self #

Creates a new file info structure.


Class Method Detail

def self.g_type : UInt64 #

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


Instance Method Detail

def access_date_time : GLib::DateTime? #

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.

If nanosecond precision is needed, %G_FILE_ATTRIBUTE_TIME_ACCESS_NSEC must be queried separately using g_file_info_get_attribute_uint32().


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.

%G_FILE_ATTRIBUTE_TIME_ACCESS_NSEC will be cleared.


def attribute_as_string(attribute : String) : String? #

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


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.


def attribute_byte_string(attribute : String) : String? #

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


def attribute_data(attribute : String) : Bool #

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


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.


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.


def attribute_mask=(mask : Gio::FileAttributeMatcher) : Nil #

Sets @mask on @info to match specific attribute types.


def attribute_object(attribute : String) : GObject::Object? #

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


def attribute_status(attribute : String) : Gio::FileAttributeStatus #

Gets the attribute status for an attribute key.


def attribute_string(attribute : String) : String? #

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


def attribute_stringv(attribute : String) : Enumerable(String)? #

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


def attribute_type(attribute : String) : Gio::FileAttributeType #

Gets the attribute type for an attribute key.


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.


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.


def clear_status : Nil #

Clears the status information from @info.


def content_type : String? #

Gets the file's content type.


def content_type=(content_type : String) : Nil #

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


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.


def creation_date_time : GLib::DateTime? #

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.

If nanosecond precision is needed, %G_FILE_ATTRIBUTE_TIME_CREATED_NSEC must be queried separately using g_file_info_get_attribute_uint32().


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.

%G_FILE_ATTRIBUTE_TIME_CREATED_NSEC will be cleared.


def deletion_date : GLib::DateTime? #

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.


def display_name : String #

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


def display_name=(display_name : String) : Nil #

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


def dup : Gio::FileInfo #

Duplicates a file info structure.


def edit_name : String #

Gets the edit name for a file.


def edit_name=(edit_name : String) : Nil #

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


def etag : String? #

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


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


def file_type=(type : Gio::FileType) : Nil #

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


def has_attribute(attribute : String) : Bool #

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


def has_namespace(name_space : String) : Bool #

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


def icon : Gio::Icon? #

Gets the icon for a file.


def icon=(icon : Gio::Icon) : Nil #

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


def is_backup : Bool #

Checks if a file is a backup file.


def is_hidden : Bool #

Checks if a file is hidden.


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.


def is_symlink : Bool #

Checks if a file is a symlink.


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.


def list_attributes(name_space : String?) : Enumerable(String)? #

Lists the file info structure's attributes.


def modification_date_time : GLib::DateTime? #

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.

If nanosecond precision is needed, %G_FILE_ATTRIBUTE_TIME_MODIFIED_NSEC must be queried separately using g_file_info_get_attribute_uint32().


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.

%G_FILE_ATTRIBUTE_TIME_MODIFIED_NSEC will be cleared.


def modification_time : GLib::TimeVal #

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


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.

%G_FILE_ATTRIBUTE_TIME_MODIFIED_NSEC will be cleared.


def name : Path #

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


def name=(name : String) : Nil #

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


def remove_attribute(attribute : String) : Nil #

Removes all cases of @attribute from @info if it exists.


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.


def set_attribute_boolean(attribute : String, attr_value : Bool) : Nil #

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


def set_attribute_byte_string(attribute : String, attr_value : String) : Nil #

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


def set_attribute_int32(attribute : String, attr_value : Int32) : Nil #

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


def set_attribute_int64(attribute : String, attr_value : Int64) : Nil #

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


def set_attribute_object(attribute : String, attr_value : GObject::Object) : Nil #

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


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.


def set_attribute_string(attribute : String, attr_value : String) : Nil #

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


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


def set_attribute_uint32(attribute : String, attr_value : UInt32) : Nil #

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


def set_attribute_uint64(attribute : String, attr_value : UInt64) : Nil #

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


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.


def size=(size : Int64) : Nil #

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


def sort_order : Int32 #

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


def sort_order=(sort_order : Int32) : Nil #

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


def symbolic_icon : Gio::Icon? #

Gets the symbolic icon for a file.


def symbolic_icon=(icon : Gio::Icon) : Nil #

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


def symlink_target : String? #

Gets the symlink target for a given #GFileInfo.


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.


def unset_attribute_mask : Nil #

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