Ottenere alcune informazioni generali sui file
Vai alla navigazione
Vai alla ricerca
Per ottenere alcune informazioni generali sui file, è possibile operare con almeno due risorse.
Usando la funzione Stat() propria di Gambas
Le modalità di utilizzo della funzione di Gambas Stat() è descritta nella seguente pagina.
Usando la funzione stat() di C
Per utilizzare la funzione stat() di C, bisognerà porla in una libreria condivisa .so esterna, appositamente realizzata da noi. La funzione contenuta da tale libreria passerà al programma principale Gambas un Puntatore alla Struttura che viene riempita dalla funzione stat().
Dunque la libreria esterna .so potrà essere del seguente tenore:
#include <sys/stat.h>
struct stat status;
int Chiama_stat(const char *s, struct stat *st) {
int r;
r = stat(s, &status);
*st = status;
return r;
}
Il codice Gambas potrà essere il seguente:
Public Struct STATUS_File
st_dev As Long
st_ino As Long
st_mode As Integer
st_nlink As Integer
st_uid As Integer
st_gid As Integer
st_rdev As Long
__pad1 As Long
st_size As Long
st_blksize As Integer
__pad2 As Integer
st_blocks As Long
st_atime As Long
st_atime_nsec As Long
st_mtime As Long
st_mtime_nsec As Long
st_ctime As Long
st_ctime_nsec As Long
__unused4 As Integer
__unused5 As Integer
End Struct
Private Extern Chiama_stat(s As String, st As STATUS_File) As Integer In "/tmp/libSTATUS"
Public Sub Main()
Dim p As Pointer
Dim stS As New STATUS_File
Dim i As Integer
' Crea la libreria esterna .so da noi scritta:
Shell "gcc -o /tmp/libSTATUS.so " & Application.Path &/ "libSTATUS.c -shared -fPIC" Wait
p = Alloc(144)
i = Chiama_stat("/percorso/del/file", p)
If i <> 0 Then Error.Raise("Errore alla funzione 'stat()' !")
stS = p
' Vediamo come esempio qualche valore del file:
With stS
Print .st_dev
Print .st_uid
Print .st_gid
Print .st_size; " byte"
End With
Free(p)
End