现在的位置: 首页 > 综合 > 正文

继续目录操作

2013年11月13日 ⁄ 综合 ⁄ 共 631字 ⁄ 字号 评论关闭
#include <dirent.h>
DIR *opendir(char *dirname);
struct dirent *readdir (DIR *dir) ;
int closedir(DIR *dir);

#include <stdio.h>
#include 
<errno.h>
#include 
<dirent.h>
int main (int argc,char *argv[] ) 
{
    DIR 
*dir;
    
struct dirent *entry;
    
    
if ( argc != 2)
    
{
        fprintf(stderr,
"usage : %s <dirname>  ",argv[0] ,strerror( errno )  ) ;
        
return 1;
    }

    dir 
= opendir( argv[1] ); 
    
if (dir ==NULL) 
    
{
        fprintf( stderr,
"%s",strerror(errno));
        
return 1;
    }

    
while ( (entry = readdir(dir) ) !=NULL)
        printf(
"%d %s  ",entry -> d_ino, entry-> d_name);
    closedir(dir);
    
return 0;
}

        
    
    

 

抱歉!评论已关闭.