#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include<iostream>
using namespace std;
#define MAX_LEN 65535
void test_list_files(){
DIR *dir;
struct dirent *ptr;
char *flow[MAX_LEN];
int num = 0, i = 0;
if ((dir=opendir("/")) == NULL)
{
cerr<<"Open dir error..."<<endl;
return ;
}
// readdir() return next enter point of directory dir
while ((ptr=readdir(dir)) != NULL)
{
flow[num] = (char*)malloc(sizeof(char));
strcpy(flow[num], ptr->d_name);
num++;
}
for(i = 0; i < num; i++)
{
cout<<flow[i]<<endl;
}
closedir(dir);
}
linux下c++读文件夹下的文件及文件夹笔记
最新推荐文章于 2025-01-08 17:52:39 发布