c - How to display st_atime and st_mtime -


I want to display my two attributes from the structure state

  struct stat {dev_t St_dev; ID of ID / IOITT_iOON files; / * Inode number * / mode_t st_mode; / * Security * / nlink_t st_nlink; / * Number of hard links * / uid_t st_uid; / * Owner User ID * / gid_t st_gid; / * Owner's Group ID * / dev_t st_rdev; / * Device ID (if special file) * / off_t st_size; / * Total size, bytes * / blksize_t st_blksize; / * File system I / O * / blkcnt_t blocks for st_blocks; / * 512 b Block Allocated * * / time_t st_atime; / * Last access time * / time_t st_mtime; / Last revision time * / time_t st_ctime; / * Last status change time * /   

};

This is my code which I reached for the last time and the last modified folder / file

  struct tm * time; Four buffers [200]; Time = local time (file_info.st_atime); Stufftime (buffer, size (buffer), "% d.% M %% Y% H:% M:% s", time); Printf ("% s \ n", buffer); Time = local time (file_info.st_mtime); Stufftime (buffer, size (buffer), "% d.% M %% Y% H:% M:% s", time); Printf ("% s \ n", buffer);   

I want to display manual red time and date such as 15.03.1952 23:11:34 as a folder / file information that has been last modified or reached in Linux

It removes slightly from your code in terms of style, but perhaps it is useful?

  #include & lt; Time.h> # Include & lt; Stdio.h & gt; # Include & lt; Sys / stat.h & gt; # Include & lt; Stdlib.h & gt; Char * formatdate (char * str, time_t val) {strftime (str, 36, "% d.% M% Y% H:% M:% S", local time (& amp; val)); Return str; } Int main () {int errno; Const char * filename; Filename = "stat.c"; Errno = 0; Struct stat * file_info = malloc (form state); If (lstat (file name, file_info)! = 0) {false ("error"); Exit (1); } Four dates [36]; Printf ("access:% s \ n", formatted (date, file_info-> st_atime)); Printf ("Modify:% s \ n", formatted (date, file_info-> st_mtime)); Printf ("Change:% s \ n", Formatate (date, file_info-> st_ctime)); Free (file_info); Return 0; }    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -