class Gio::FileInfo

Overview

Stores information about a file system object referenced by a 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 the file attributes document for more information on how GIO handles file attributes.

To obtain a GFileInfo for a Gio::File, use Gio::File#query_info (or its async variant). To obtain a GFileInfo for a file input or output stream, use Gio::FileInputStream#query_info or 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 Gio::File#attributes_from_info= or Gio::File#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 Gio::FileInfo#size=. You may call Gio::File#query_settable_attributes and Gio::File#query_writable_namespaces to discover the settable attributes of a particular file at runtime.

The direct accessors, such as Gio::FileInfo#name, are slightly more optimized than the generic attribute accessors, such as Gio::FileInfo#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 Gio::FileInfo#has_attribute or Gio::FileInfo#list_attributes to check what attributes are specified for a GFileInfo.

Gio::FileAttributeMatcher 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.


Class Method Detail

def self.g_type : UInt64 #

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


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.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_TIME_ACCESS. If %G_FILE_ATTRIBUTE_TIME_ACCESS_USEC is provided, the resulting #GDateTime will additionally 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 | Nil #

Gets the value of an 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 | Nil #

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_file_path(attribute : String) : Path | Nil #

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.


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 | Nil #

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 | Nil #

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) | Nil #

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 | Nil #

Gets the file's content type.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_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 of dest_info, and then copies all of the file attributes from src_info to dest_info.


def creation_date_time : GLib::DateTime | Nil #

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

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_TIME_CREATED. If %G_FILE_ATTRIBUTE_TIME_CREATED_USEC is provided, the resulting #GDateTime will additionally 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 | 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.


def display_name : String #

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

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.


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.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME.


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 | Nil #

Gets the [entity tag][iface@Gio.File#entity-tags] for a given #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.

It is an error to call this if the #GFileInfo does not contain %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().

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_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 hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def icon : Gio::Icon | Nil #

Gets the icon for a file.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_ICON.


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.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP.


def is_hidden : Bool #

Checks if a file is hidden.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_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.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_IS_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 | Nil) : Enumerable(String) | Nil #

Lists the file info structure's attributes.


def modification_date_time : GLib::DateTime | Nil #

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

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_TIME_MODIFIED. If %G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC is provided, the resulting #GDateTime will additionally 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.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_TIME_MODIFIED. If %G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC is provided it will be used too.

DEPRECATED


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.

DEPRECATED


def name : Path #

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

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_NAME.


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_file_path(attribute : String, attr_value : String) : Nil #

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.


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.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_SIZE.


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.

It is an error to call this if the #GFileInfo does not contain %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 | Nil #

Gets the symbolic icon for a file.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_SYMBOLIC_ICON.


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 : Path | Nil #

Gets the symlink target for a given #GFileInfo.

It is an error to call this if the #GFileInfo does not contain %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET.


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.