免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 954 | 回复: 1
打印 上一主题 下一主题

[SCO UNIX] 求助:如何遍历目录下的所有文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-12-17 16:47 |只看该作者 |倒序浏览
在sco_unix5.0.5下:
      如何遍历目录下的所有文件。

#include <sys/types.h>;
#include <sys/stat.h>;
#include <sys/dir.h>;
#include <sys/dirent.h>;
#include <string.h>;
#include <stdio.h>;  
#include <dirent.h>;

main()
{
   struct direct *dp;
   DIR *dirp;
   
   struct stat sbuf;
   int i;
       
   dp  =(struct direct *)malloc(sizeof(struct direct ));
   dirp=(DIR *)malloc(sizeof(DIR));
   memset(tmp,0,255);
       
   dirp = opendir( "." );
   
   i=1;

   while((dp = readdir( dirp )) != NULL ) {
         if(dp->;d_ino==0)  continue;
               
         strcpy(tmp,dp->;d_name);
         printf("[%02d]dp->;d_name=%s,len=%d,d_reclen=%d\n",i,dp->;d_name,strlen(dp->;d_name),dp->;d_reclen);  
         i++;
   }
   
   closedir( dirp );
   
   free(dp);
   free(dirp);
}


==========================
运行结果:
[01]dp->;d_name=,len=0,d_reclen=12
[02]dp->;d_name=,len=0,d_reclen=16
[03]dp->;d_name=,len=1,d_reclen=24
[04]dp->;d_name=,len=1,d_reclen=20
[05]dp->;d_name=,len=1,d_reclen=20
[06]dp->;d_name=,len=1,d_reclen=12
[07]dp->;d_name=,len=1,d_reclen=20
[08]dp->;d_name=,len=0,d_reclen=16
[09]dp->;d_name=,len=1,d_reclen=16


++++++++++++++++++++++
why?
    dp->;d_name 的内容为空!

论坛徽章:
0
2 [报告]
发表于 2003-12-18 14:35 |只看该作者

求助:如何遍历目录下的所有文件

去调头文件中的
#include <sys/dir.h>;


这样就可以了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP