免费注册 查看新帖 |

Chinaunix

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

請幫助我,謝謝! [复制链接]

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:51:16
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-29 18:29 |显示全部楼层 |倒序浏览
我寫了個 linux 讀取目錄下所有文件打印出來,包括子目錄裏的文件
但是有問題,本人很菜,看了3個小時都沒看出錯誤.希望大家幫忙.指點一下!!萬分感謝!!

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

void find(DIR *tdp)
{
   DIR *tmpdp;
   struct dirent *dirp;
   while((dirp = readdir(tdp)) != NULL)
   {
      if ((tmpdp = opendir(dirp->d_name)) == NULL)
      {
         printf("%s\n",dirp->d_name);
      }
      else
     {
       find(tmpdp);
      }
   }

int main()
{
   DIR *dp;
   if((dp = opendir("/home/freedino/test")) == NULL)
   {
      printf("can't open \n");
      exit(2);
   }
   find(dp);
}

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:51:16
2 [报告]
发表于 2006-10-13 17:57 |显示全部楼层

謝謝大家

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

void find( char *path, char *src)
{
   DIR *tmpdp;
   struct dirent *dirp;
   char s[1000];

   sprintf( s, "%s/%s", path, src);
   if( (tmpdp=opendir( s)) == NULL ){
      return;
   }

   fprintf( stderr, "%s\n", s );
   while((dirp = readdir(tmpdp)) != NULL){
      if (strcmp(dirp->d_name,".") == 0 || strcmp(dirp->d_name,"..") == 0)
         continue;

      find( s, dirp->d_name );
   }
}


int main( int argc, void **argv )
{
   find( "/home/freedino/", "test");
   return 0;
}


謝謝你們的幫助,謝謝!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP