国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

深入探討:linux中遍歷文件夾下的所有文件

2024-08-28 00:02:09
字體:
來源:轉載
供稿:網友
linux C 遍歷目錄及其子目錄
復制代碼 代碼如下:
#include <stdio.h> 
#include <string.h>
#include <stdlib.h> 
#include <dirent.h> 
#include <sys/stat.h> 
#include <unistd.h> 
#include <sys/types.h>
using namespace std;
void listDir(char *path) 

        DIR              *pDir ; 
        struct dirent    *ent  ; 
        int               i=0  ; 
        char              childpath[512]; 

        pDir=opendir(path); 
        memset(childpath,0,sizeof(childpath)); 

 
        while((ent=readdir(pDir))!=NULL) 
        { 

                if(ent->d_type & DT_DIR) 
                { 

                        if(strcmp(ent->d_name,".")==0 || strcmp(ent->d_name,"..")==0) 
                                continue; 

                        sprintf(childpath,"%s/%s",path,ent->d_name); 
                        printf("path:%s/n",childpath); 

                        listDir(childpath); 

                } 
else
{
cout<<ent->d_name<<endl;
}
        } 



int main(int argc,char *argv[]) 

        listDir(argv[1]); 
        return 0; 
}

Linux C :遍歷輸出指定目錄下的所有文件
在Linux下opendir()、readdir()和closedir()這三個函數主要用來遍歷目錄。在使用這三個函數前必
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永川市| 汤阴县| 长寿区| 桐庐县| 乐都县| 台中县| 临沭县| 秦皇岛市| 凤翔县| 伊宁市| 张北县| 铁岭县| 南江县| 临武县| 五大连池市| 屏山县| 宁城县| 河曲县| 涿州市| 陇川县| 柳江县| 横峰县| 恩施市| 汾西县| 镇平县| 望城县| 拜城县| 桦川县| 南京市| 东辽县| 广州市| 灵山县| 中西区| 双流县| 安阳市| 神农架林区| 大丰市| 大冶市| 丰原市| 织金县| 邯郸市|