Linux under struct dirent,dir,struct stat use example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.