Conoscere il tipo di file mediante le funzioni esterne del API di libgio

Da Gambas-it.org - Wikipedia.

La libreria Libgio fornisce un'astrazione del file system che permette alle applicazioni di accedere ai file locali e remoti.

E' possibile con alcune funzioni della libreria Libgio sapere a quale tipo un file appartiene. La tipologia è indicata nel file /usr/include/glib-2.0/gio/gioenums.h, ed è così specificata:

* GFileType:
* @G_FILE_TYPE_UNKNOWN: File's type is unknown.
* @G_FILE_TYPE_REGULAR: File handle represents a regular file.
* @G_FILE_TYPE_DIRECTORY: File handle represents a directory.
* @G_FILE_TYPE_SYMBOLIC_LINK: File handle represents a symbolic link
*    (Unix systems).
* @G_FILE_TYPE_SPECIAL: File is a "special" file, such as a socket, fifo,
*    block device, or character device.
* @G_FILE_TYPE_SHORTCUT: File is a shortcut (Windows systems).
* @G_FILE_TYPE_MOUNTABLE: File is a mountable location.

Sarà necessario richiamare la libreria (nella sua attuale versione): libgio-2.0.so.0.4002.0


Mostriamo di seguito un semplice esempio pratico:

Library "libgio-2.0:0.4002.0"

Private Enum G_FILE_QUERY_INFO_NONE = 0, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS
Private Enum G_FILE_TYPE_UNKNOWN = 0, G_FILE_TYPE_REGULAR, G_FILE_TYPE_DIRECTORY, G_FILE_TYPE_SYMBOLIC_LINK,
             G_FILE_TYPE_SPECIAL, G_FILE_TYPE_SHORTCUT, G_FILE_TYPE_MOUNTABLE

' GFile * g_file_new_for_path (const char *path)
' Constructs a GFile for a given path. This operation never fails.
Private Extern g_file_new_for_path(path As String) As Pointer

' GFileType   g_file_query_file_type (GFile *file, GFileQueryInfoFlags flags, GCancellable *cancellable)
' Inspects the GFileType of a file.
Private Extern g_file_query_file_type(gfile As Pointer, flags As Integer, cancellable As Pointer) As Integer


Public Sub Main()

 Dim gf As Pointer
 Dim tipo As Integer

  gf = g_file_new_for_path("/percorso/del/file")
  If IsNull(gf) Then Error.Raise("Impossibile creare un oggetto GFile con il percorso del file impostato !")
  
  tipo = g_file_query_file_type(gf, G_FILE_QUERY_INFO_NONE, 0)
  
  Print tipo

End