Only C/C++

半亩方塘 天光云影

  C++博客 ::  :: 新随笔 :: 联系 ::  :: 管理 ::
  48 随笔 :: 4 文章 :: 142 评论 :: 0 Trackbacks
#include   <stdio.h> 
#include   
<dirent.h> 
#include   
<string.h> 

 typedef   
struct   FileList 
    

        
char   filename[64]; 
        
struct   FileList   *next; 
    }
FILENODE; 

FILENODE
*  getFiles(char *dir/*文目录*/)
{
   DIR   
*directory_pointer; 
   
struct   dirent   *entry; 
   directory_pointer
=opendir(dir);
   
struct FileList start;
   
struct FileList *filesNode;
    start.next
=NULL; 
        filesNode
=&start; 
        
while   ((entry=readdir(directory_pointer))!=NULL) 
        

            filesNode
-> next=(struct   FileList   *)malloc(sizeof(struct   FileList)); 
            filesNode
=filesNode-> next; 
            strcpy(filesNode
-> filename,entry-> d_name); 
            filesNode
-> next=NULL; 
        }
 
        closedir(directory_pointer); 
        filesNode
=start.next;
        
return filesNode;         
}


int   main() 

    
struct FileList *filesNode;
    
char dir[100]="D:\\down";  
    filesNode
=getFiles(dir);
   
    
    
if (filesNode==NULL)
    
{
    printf(
"没有成功");
    
return 0;
    }

    
while(filesNode) 
    

    printf( 
"%s\n ",filesNode-> filename); 
    filesNode
=filesNode-> next; 
    }
  
  
    system(
"pause");
    
return 0;
}

posted on 2008-08-28 18:10 JetSun 阅读(893) 评论(0)  编辑 收藏 引用 所属分类: c/c++

专题:Android  iPad jQuery Chrome OS

博客园首页  IT新闻  知识库  学英语  C++程序员招聘
标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]
每天10分钟,轻松学英语
网站导航: