Linux under struct dirent,dir,struct stat use example
In the following example, read the folder in the directory, file, and output some property values, specific related structure definition, can refer to:
http://www.liweifan.com/2012/05/13/linux-system-function-files-operation/
Http://www.360doc.com/content/11/0110/16/4559801_85509847.shtml
/** linux struct dirent,dir,struct stat* date:2015-7-16* author:zhang* compiled by gcc*/#include <stdio.h> #include <sys/stat.h> #include <dirent.h> #include <string.h>int main (int argc,char **argv) {struct dirent * DIRP; struct STAT buffer; DIR *DP; Structure, see http://www.liweifan.com/2012/05/13/linux-system-function-files-operation/if (argc! = 2) {printf (" argument is error!\n "); return 0;} if (DP = Opendir (argv[1)) = = NULL) {printf ("File path is error!\n"); return 0;} while (DIRP = Readdir (DP)) {printf ("FileName:%s\n", dirp->d_name);//File name stat (dirp->d_name,&buffer);// printf ("%d\n", stat (dirp->d_name,&buffer));p rintf ("St_mode:%d\n", Buffer.st_mode); File access Permissions printf ("St_uid:%d\n", buffer.st_uid); Owner user identification number printf ("St_mtime:%d\n", buffer.st_mtime);//The time that the file was last modified by printf ("\ n"); Closedir (DP); return 0;}
Reference documents:
http://www.liweifan.com/2012/05/13/linux-system-function-files-operation/
Http://www.360doc.com/content/11/0110/16/4559801_85509847.shtml
http://www.cplusplus.com/forum/unices/16005/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Linux under struct dirent,dir,struct stat use example