C语言判断一个字符串是文件还是文件夹

来源:互联网 发布:动态壁纸软件 编辑:程序博客网 时间:2024/04/28 23:09
 //头文件  2 #include "stdio.h"  3 #include "stdlib.h"  4 #include <sys/stat.h>  5 //代码  6 int main()  7 {  8     char* fileName = "aa.txt";  9     struct _stat buf; 10     int result; 11     result = _stat( fileName, &buf ); 12     if(_S_IFDIR & buf.st_mode){ 13         printf("folder\n"); 14     }else if(_S_IFREG & buf.st_mode){ 15         printf("file\n"); 16     } 17 18     return 0; 19 } 

0 0
原创粉丝点击