Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

which Stuct def is used to get filetime info?

Status
Not open for further replies.

JaybOt

Programmer
Apr 18, 2001
101
GB
Hi all,

Can anyone recall the struct definition used to get a files creation times? (unix C++) I think the call is passed two arguments, one is the filename, and the other is this struc def; Not sure if this makes any sence!

Also, if you could provide an example of how it is used (defined) it would be most appreciated.

Regards,
JayB0t [afro]

"Always know what you say, but don't always say what you know!"
 
Use the fstat() API call, this uses the "stat" structure which has the following members:

struct stat {
dev_t st_dev; /* device */
ino_t st_ino; /* inode */
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 type (if inode device) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for filesystem I/O */
blkcnt_t st_blocks; /* number of 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 change */
};


st_ctime is set when the inode data is changed, ie. the file is created, the mode is changed, or the owner or group is changed. I think this is as close as you can get to a definitive creation date.

To use you would use the following code (note there is no error checking - its pseudo-code)

struct stat s_stat;

if(fstat("myfile","&s_stat)!=-1)
printf("File was created at %s",ctime(s_stat.st_ctime));
else
error_handling




 
Thats great, Thanks!

Thats exactly what i was thinking of - struct s_stat - and well done! I didn't think anyone would get it from that criptic clue! [thumbsup2]

Regards,
JayB0t [afro]


"Always know what you say, but don't always say what you know!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top