linux C 读取目录文件并统计文件数
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <string.h>
#define MAX 1024
int get_file_count(char *root)
{
DIR *dir;
struct dirent * ptr;
int total = 0;
char path[MAX];
dir = opendir(root); /* 打开目录*/
if(dir == NULL)
{
perror("fail to open dir");
exit(1);
}
errno = 0;
while((ptr = readdir(dir)) != NULL)
{
//顺序读取每一个目录项;
//跳过“..”和“.”两个目录
if(strcmp(ptr->d_name,".") == 0 || strcmp(ptr->d_name,"..") == 0)
{
continue;
}
//printf("%s%s\n",root,ptr->d_name);
//如果是目录,则递归调用 get_file_count函数
if(ptr->d_type == DT_DIR)
{
sprintf(path,"%s%s/",root,ptr->d_name);
//printf("%s\n",path);
total += get_file_count(path);
}
if(ptr->d_type == DT_REG)
{
total++;
printf("%s%s\n",root,ptr->d_name);
}
}
if(errno != 0)
{
printf("fail to read dir"); //失败则输出提示信息
exit(1);
}
closedir(dir);
return total;
}
int main(int argc, char * argv[])
{
int total;
if(argc != 2)
{
printf("wrong usage\n");
exit(1);
}
total = get_file_count(argv[1]);
printf("%s ha %d files\n",argv[1],total);
return 0;
}
相关文档:
1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI) 就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......
Boss说,要看OpenGL,看了快一个月,总算出了个像样的东西,用C写了个3D迷宫,
虽然只有350行
代码,不过边学边写,足足写了一周时间,还是小有成就感的,活活活!
&n ......
Linux 内核启动分析(转)
Linux 内核启动分析
1. 内核启动地址
1.1. 名词解释
ZTEXTADDR
解压代码运行的开始地址。没有物理地址和虚拟地址之分,因为此时MMU处于关闭状态。这个地址不一定时RAM的地址,可以是支持读写寻址的flash等存储中介。
Start address of ......
正式实习一周,有点感触。本来就没指望能成为什么技术大牛,用自己调侃的话来说就是“混口饭吃”。不过老大对me的期望值那么高,经理管得这么严,压力颇大。对自己挺失望,没能开好头,有点对不起这么成功的老大。还好没准备做什么大事,要不然这性格得费多大力气才能重塑。。。
都是逼出来的,被经理训后,一天 ......