c++ linux 遍历文件夹下的文件
Posted nowheretrix
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c++ linux 遍历文件夹下的文件相关的知识,希望对你有一定的参考价值。
#include
#include "fstream"
#include
#include
#include
#include
using namespace std;
string key="aabbccdd1122334455absacsafasfasvsapocasppf123oawirpw";
int lenOfAllKey=256;
int main(){
DIR * dir;
struct dirent * ptr;
char file_list[100][40];
int i=0;
char srcFile1[1][100];
printf("111\n");
string rootdirPath = "/home/jyh/code/rc4加密/password/";
string
string x,dirPath;
dir = opendir((char *)rootdirPath.c_str()); //打开一个目录
while((ptr = readdir(dir)) != NULL) //循环读取目录数据
{
printf("d_name : %s\n", ptr->d_name); //输出文件名
x=ptr->d_name;
dirPath = rootdirPath + x;
//printf("d_name : %s\n", dirPath.c_str()); //输出文件绝对路径
// x = dirPath.c_str();
strcpy(srcFile1[i],dirPath.c_str()); //存储到数组
if ( ++i>=100 ) break;
}
printf("111\n");
closedir(dir);//关闭目录指针
}以上是关于c++ linux 遍历文件夹下的文件的主要内容,如果未能解决你的问题,请参考以下文章
求一个windows下的纯C语言实现的文件夹遍历程序,要可以遍历子文件夹,不要unix下的和C++的。
linux 下的文件目录操作之遍历目录
Python中如何遍历指定目录下的所有文件?
请教,如何遍历一个文件夹下的所有文本文件
交互式shell脚本遍历文件目录下的所有文件和目录(绝对路径)
交互式shell脚本遍历文件目录下的所有文件和目录(绝对路径)