Equivalent function of timeCreated for Linux

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue May 1 15:53:16 UTC 2018


On Tuesday, May 01, 2018 15:41:07 Vino via Digitalmars-d-learn wrote:
> Hi All,
>
>   Request your help, what is the equivalent function of
> timeCreated(Windows) for Linux. Or how do i get the file creation
> date and time in Linux using D.

AFAIK, no filesystems on Linux keep track of that information, and if they
do, you can't get at it via the normal OS API calls for getting file
information. The closest that you're likely to get was the time that the
file was last modified. The OS API call for getting information on POSIX
systems is the stat command, and as can be seen on the man page

https://linux.die.net/man/2/stat

this is the information provided on Linux:

struct stat {
    dev_t     st_dev;     /* ID of device containing file */
    ino_t     st_ino;     /* inode number */
    mode_t    st_mode;    /* protection */
    nlink_t   st_nlink;   /* number of hard links */
    uid_t     st_uid;     /* user ID of owner */
    gid_t     st_gid;     /* group ID of owner */
    dev_t     st_rdev;    /* device ID (if special file) */
    off_t     st_size;    /* total size, in bytes */
    blksize_t st_blksize; /* blocksize for file system I/O */
    blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
    time_t    st_atime;   /* time of last access */
    time_t    st_mtime;   /* time of last modification */
    time_t    st_ctime;   /* time of last status change */
};

The only fields related to time are

    time_t    st_atime;   /* time of last access */
    time_t    st_mtime;   /* time of last modification */
    time_t    st_ctime;   /* time of last status change */

and the file creation time is not one of them. That's why D's std.file does
not provide a way to get at the file creation time on any non-Windows
systems. Windows tracks the file creation and has calls to provide that
information, whereas POSIX systems do not. So, std.file provides that
information on Windows but not on other systems.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list