欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

C/C++獲取目錄下的文件列表信息

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

1.數(shù)據(jù)結(jié)構(gòu)

復(fù)制代碼 代碼如下:

struct dirent
{
    long d_ino;                 /* inode number 索引節(jié)點(diǎn)號 */
    off_t d_off;                /* offset to this dirent 在目錄文件中的偏移 */
    unsigned short d_reclen;    /* length of this d_name 文件名長 */
    unsigned char d_type;        /* the type of d_name 文件類型 */   
    char d_name [NAME_MAX+1];   /* file name (null-terminated) 文件名,最長255字符 */
}

struct __dirstream
  {
    void *__fd;                        /* `struct hurd_fd' pointer for descriptor.  */
    char *__data;                /* Directory block.  */
    int __entry_data;                /* Entry number `__data' corresponds to.  */
    char *__ptr;                /* Current pointer into the block.  */
    int __entry_ptr;                /* Entry number `__ptr' corresponds to.  */
    size_t __allocation;        /* Space allocated for the block.  */
    size_t __size;                /* Total valid data in the block.  */
    __libc_lock_define (, __lock) /* Mutex lock for this structure.  */
  };

typedef struct __dirstream DIR;

2.程序示例
其中程序中win不支持文件類型(d_type),可以根據(jù)文件名稱后綴來判斷文件類型;linux可以直接使用d_type判斷是目錄還是文件。

復(fù)制代碼 代碼如下:

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

int main(){
    DIR    *dir;
    struct    dirent    *ptr;
    dir = opendir("."); ///open the dir

    while((ptr = readdir(dir)) != NULL) ///read the list of this dir
    {
        #ifdef _WIN32
            printf("d_name: %s\n", ptr->d_name);
        #endif
        #ifdef __linux
            printf("d_type:%d d_name: %s\n", ptr->d_type,ptr->d_name);
        #endif
    }
    closedir(dir);
    return 0;
}

程序輸出:

上一篇:實(shí)現(xiàn)去除c語言注釋的小工具

欄    目:C語言

下一篇:顯示內(nèi)存狀態(tài)示例分享

本文標(biāo)題:C/C++獲取目錄下的文件列表信息

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/3757.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有