易截截图软件、单文件、免安装、纯绿色、仅160KB

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;
}


相关文档:

用C写的3D迷宫

          Boss说,要看OpenGL,看了快一个月,总算出了个像样的东西,用C写了个3D迷宫,
虽然只有350行
       代码,不过边学边写,足足写了一周时间,还是小有成就感的,活活活!
         &n ......

linux chown与chgrp 的用法

指令名称 : chown
使用权限 : root
使用方式 :
chown [-cfhvR] [--version] user[:group] file...
说明 : 利用 chown 可以将档案的拥有者加以改变。这个指令只有是由系统管理者(root)所使用,一般使用者没有权限可以改变别人的档案拥有者,也没有权限可以自己的档案拥有者改设为别人。只有系统管理者(root)才有这样 ......

firefox 简单 插件编译 【linux】

#ifdef XP_UNIX
/*
* Set up the plugin function table that Netscape will use to
* call us. Netscape needs to know about our version and size
* and have a UniversalProcPointer for every function we
* implement.
*/
pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
......

为linux内核构建最小的根文件系统 一步一步精简

linux内核init进程函数的部分代码如下: 01 if (execute_command)
02 run_init_process(execute_command);
03
04 run_init_process("/sbin/init");
05 run_init_process("/etc/init");
06 run_init_process("/bin/init");
07 run_init_process("/ ......

building firefox 【linux】

  
sudo apt-get build-dep firefox
若出现下面的错误:
不能满足软件包 firefox 所要求的构建依赖关系
请将 /etc/apt/sources.list 改为默认的源 有就是 装完系统后自带的:
#deb cdrom:[Ubuntu 9.04 _Jaunty Jackalope_ - Release i386 (20090421.3)]/ jaunty main restricted
# See http://help.ubuntu ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号