La aproximación más aproximada a 'fecha de creación' es st_ctime
miembro en el struct stat
, pero eso realmente registra la última vez que cambió el inodo. Si crea el archivo y nunca modifica su tamaño o permisos, eso funciona como una hora de creación. De lo contrario, no hay registro de cuándo se creó el archivo, al menos en los sistemas Unix estándar.
para sus propósitos, ordenar por st_mtime
... o conseguir los archivos nombrados con una marca de tiempo en el nombre.
Tenga en cuenta que si está en Darwin (Mac OS X), el tiempo de creación está disponible. Desde la página del manual de stat(2)
:
Sin embargo, cuando se define la macro _DARWIN_FEATURE_64_BIT_INODE
, la estructura stat A continuación, se define como:
struct stat { /* when _DARWIN_FEATURE_64_BIT_INODE is defined */
dev_t st_dev; /* ID of device containing file */
mode_t st_mode; /* Mode of file (see below) */
nlink_t st_nlink; /* Number of hard links */
ino_t st_ino; /* File serial number */
uid_t st_uid; /* User ID of the file */
gid_t st_gid; /* Group ID of the file */
dev_t st_rdev; /* Device ID */
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last status change */
struct timespec st_birthtimespec; /* time of file creation(birth) */
off_t st_size; /* file size, in bytes */
blkcnt_t st_blocks; /* blocks allocated for file */
blksize_t st_blksize; /* optimal blocksize for I/O */
uint32_t st_flags; /* user defined flags for file */
uint32_t st_gen; /* file generation number */
int32_t st_lspare; /* RESERVED: DO NOT USE! */
int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */
};
Nota el campo st_birthtimespec
. Tenga en cuenta, también, que todas las veces están en struct timespec
valores, por lo que hay menos de un segundo de tiempo (tv_nsec
da resolución de nanosegundos). POSIX 2008 <sys/stat.h>
requiere que el tiempo struct timespec
se mantenga en los tiempos estándar; Darwin sigue eso.
'fstat' no obtiene un valor de marca de tiempo "archivo creado" porque muchos sistemas de ficheros don' t rastrea esos datos. ¿Con qué sistema de archivos estás trabajando? –
Uno que es estándar para el último escritorio de Ubuntu, supongo - estoy ejecutando mi código en la máquina virtual (reproductor vmware, para ser exactos), y dejé todos los detalles como el sistema de archivos al instalador ubuntu. – Srv19
intente 'stat (buffer, & buf)' en lugar de no-useful-here 'fopen' – mpez0