Comunidad Gambas-es
Extendiendo la clase File - Stat - Versión para impresión

+- Comunidad Gambas-es (https://gambas-es.org)
+-- Foro: Gambas (https://gambas-es.org/forum-3.html)
+--- Foro: Aplicaciones/Fragmentos de Código (https://gambas-es.org/forum-8.html)
+--- Tema: Extendiendo la clase File - Stat (/thread-335.html)



Extendiendo la clase File - Stat - tincho - 15-04-2021

Hola a todos.
De forma análoga al tema titulado Extendiendo la clase String aprovechare para compartir con ustedes algunas funciones que he ido haciendo y que a mi me resultaron útiles. He aquí la primera de ellas:
Código:
Library "libc:6"

Public Struct stat_
  st_dev As Long
  st_ino As Long
  st_nlink As Long
  st_mode As Integer
  st_uid As Integer
  st_gid As Integer
  __pad0 As Integer
  st_rdev As Long
  st_size As Long
  st_blksize As Long
  st_blocks As Long
  st_atime As Long
  st_atimensec As Long
  st_mtime As Long
  st_mtimensec As Long
  st_ctime As Long
  st_ctimensec As Long
  __glibc_reserved[3] As Long
End Struct

Private Const _STAT_VER_LINUX As Integer = 1
Private Extern __xstat(_STAT_VER As Integer, __path As String, __statbuf As Stat_) As Integer

'' <b>RAD Extension.</b><br>
'' Create a file parameters list using the GNU coreutils program stat. Note: the tags for access to the information are:<br>
'' Dev, Ino, Path, Link, Mode, SetUID, SetGID, Rdev, Size, BlkSize, Blocks, LastAccess, LastModified, LastChange<br>
'' Original <https://www.gambas-it.org/wiki/index.php?title=Stat_()>

Static Public Sub Stat(f As String) As Collection

  Dim i As Integer
  Dim st As New Stat_
  Dim inf As New Collection

  i = __xstat(_STAT_VER_LINUX, f, st)
  If i < 0 Then Error.Raise("Function error '__xstat()' !")

  With st
    inf.Add(.st_dev, "Dev")
    inf.Add(.st_ino, "Ino")
    inf.Add(f, "Path")
    inf.Add(.st_nlink, "Link")
    inf.Add(.st_mode, "Mode")
    inf.Add(.st_uid, "SetUID")
    inf.Add(.st_gid, "SetGID")
    inf.Add(.st_rdev, "Rdev")
    inf.Add(.st_size, "Size")
    inf.Add(.st_blksize, "BlkSize")
    inf.Add(.st_blocks, "Blocks")
    inf.Add(.st_atime, "LastAccess")
    inf.Add(.st_mtime, "LastModified")
    inf.Add(.st_ctime, "LastChange")
  End With

  Return inf

End
Nota: Esta función no hubiese sido posible sin el articulo que Vuott publico en la wiki el foro italiano.
Saludos.