热门关键字:  ubuntu  分区  Fedora  linux系统进程  函数

linux下的c 编程------dir scan

来源: 作者: 时间:2007-08-15 Tag: 点击:

#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>

void printdir(char *dir,int depth)
{
DIR *dp;
struct dirent *entry;
struct stat statbuf;

if((dp=opendir(dir))==NULL)
{
fprintf(2,"can not open directory :%s\n",dir);
return;
}
chdir(dir);
while((entry=readdir(dp))!=NULL)
{
lstat(entry->d_name,&statbuf);
if(S_ISDIR(statbuf.st_mode))
{
if(strcmp(".",entry->d_name)==0||strcmp("..",entry->d_name)==0)
{
continue;
}
printf("%*s%s/\n",depth,"",entry->d_name);
printdir(entry->d_name,depth+4);
}
else printf("%*s%s\n",depth,"",entry->d_name);

}
chdir("..");
closedir(dp);
}

int main()
{
printf("Directory scan of /home/lzy/prog_c:\n");
printdir("/home/lzy/prog_c",0);
  printf("done!");
exit(0);
}



相关文章:
Scaling out MySQL - Hardware today and tomorro
MySQL教会我使用GnuPG验证软件包
MySQL中MyISAM引擎与InnoDB引擎性能简单测试
mysqladmin在线帮助文档
install a MySQL source distribution
Mysql备份脚本(未验证)
每小时Dump所有mysql数据库到NAS存储设备上
MySQL数据库5.0的my.cnf配置选项
MYSQL建表实例
一些对Mysql DBA有用的脚本
MySql数据引擎简介与选择方法
通向MySQL神秘王国的图形化之路
mysql 中show 命令用法详细介绍
Linux自动备份MySQL数据库 实用方法
如何导入导出MySQL数据库
MySQL创始人力劝用户暂缓部署MySQL 5.1
mysql权限管理
Mysql自动备份脚本
升级mysql
mysql日志
MySql带参数的存储过程编写(动态执行SQL语句)
ERROR 1045 (28000): Access denied for 报错解决
sql优化
配置源码安装的MySQL同时支持多个字符集
MySQL数据表类型 数据类型
sql文件无法读取
mysql 中如何进行IP地址的存放
正在表达式在mysql中的使用
sql mode
linux安装mysql可执行安装包