C   117

fileinfo.c

Guest on 4th September 2021 05:41:41 AM

  1. #include <stdio.h>
  2. #include <dirent.h>
  3. #include <sys/stat.h>
  4. #include <sys/types.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8.  
  9. /* This program takes the name of a file as argv[1] and provide info */
  10. int main(int argc, char* argv[]){
  11.   struct stat statbuf;
  12.   stat(argv[1],&statbuf);
  13.   printf("The information for the file %s are\n", argv[1]);
  14.   printf("dir = %d\n", S_ISDIR(statbuf.st_mode));
  15.   printf("file size is %ld in bytes \n", statbuf.st_size);
  16.   printf("last modified time is %ld in seconds \n", statbuf.st_mtime);
  17.   printf("last access time is %ld in seconds \n", statbuf.st_atime);
  18.   printf("The device containing the file is %d\n", statbuf.st_dev);
  19.   printf("File serial number is %d\n\n", statbuf.st_ino);
  20.   return EXIT_SUCCESS;
  21. }

Raw Paste


Login or Register to edit or fork this paste. It's free.