zoukankan      html  css  js  c++  java
  • 文件夹操作

    1. opendir

    DIR *opendir(const char *name);
    DIR *fdopendir(int fd);

    打开一个目录,失败返回空

    2. readdir

    struct dirent *readdir(DIR *dirp);
    int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);

    读目录

    struct dirent 
    {
        ino_t          d_ino;       /* inode number 索引节点号*/
        off_t          d_off;       /* offset to the next dirent 在目录文件中的偏移*/
        unsigned short d_reclen;    /* length of this record 文件名长*/
        unsigned char  d_type;      /* type of file; not supported by all file system types 文件类型*/
        char           d_name[256]; /* filename 文件名,最长255字符*/
    };

    3. closedir

    int closedir(DIR *dirp);

    4. 举例

    DIR *dir = opendir("./");
    
    struct dirent *de;
    
    if(dir)
    {   
        while((de = readdir(dir)))
        {   
            puts(de->d_name);
        }   
    }
    
    closedir(dir);
  • 相关阅读:
    Android作业10/21
    Android作业10/07
    Android作业0930
    Android作业 0923
    第四周作业
    第七周
    第六周
    第四周作业
    3.10第二次
    jsp第一次作业
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11709917.html
Copyright © 2011-2022 走看看