自己写了一个 判断文件夹是否为空的小代码
复制代码
1//文件夹操作相关的函数的帮助
$: man 3 readdir
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <dirent.h> int isdirempty(char *dirname) { /* 打开要进行匹配的文件目录 */ DIR *dir = opendir(dirname); struct dirent *ent; if (dir == NULL) { perror("seekkey.c-98-opendir"); return -1; } while (1) { ent = readdir (dir); if (ent <= 0) { break; } if ((strcmp(".", ent->d_name)==0) || (strcmp("..", ent->d_name)==0)) { continue; } if ((ent->d_type == 4) || (ent->d_type == 8)) { return -1; } } return 0; } int main() { char *dirname = "bb"; int res = isdirempty(dirname); if (res == 0) { printf ("是空n"); } else { printf ("不是空n"); } }
转载于:https://www.cnblogs.com/etangyushan/p/3714779.html
最后
以上就是体贴春天最近收集整理的关于linux下使用c判断文件夹是否为空的小程序的全部内容,更多相关linux下使用c判断文件夹是否为空内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复