www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Equivalent function of timeCreated for Linux

reply Vino <vino.bheeman hotmail.com> writes:
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.

From,
Vino.B
May 01 2018
parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
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
May 01 2018