search inside files inside file

closed account (GTXEhUp4)
hello i am trying to make a program for specify extension finder but i have some issue how can i search inside files inside file like i have a A folder in this folder have B,C,D,E,F folders, B folder has a txt folder how can i see that ?

//heres my code


#include <iostream>
#include <dirent.h>
#include <sys/types.h>
using namespace std;
int main(void) {
DIR *dir;
struct dirent *en;
dir = opendir("C:\\Users\\BATU\\Desktop\\bestas\\deneme\\A"); //open all directory
if (dir) {
while ((en = readdir(dir)) != NULL) {
cout<<" \n"<<en->d_name; //print all directory name
}

closedir(dir); //close all directory
}
return(0);
}
You probably want to use recursion.
Use the standard filesystem library. https://en.cppreference.com/w/cpp/filesystem

For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream> 
#include <filesystem>

void list_directories( const std::filesystem::path path_to_dir )
{
	if( std::filesystem::is_directory(path_to_dir) )
    	    for( const auto& entry : std::filesystem::recursive_directory_iterator(path_to_dir) )
    		if( entry.is_directory() ) std::cout << entry.path() << '\n' ;
}

int main()
{
	list_directories( "/tmp" ) ;
}

http://coliru.stacked-crooked.com/a/ab6bb9ddc26dfca5
closed account (GTXEhUp4)
#include<filesystem> doesn't work
What compiler / IDE do you use ?

#include<filesystem> requires C++17
baduymus wrote:
#include<filesystem> doesn't work

This isn't your first go-around with <filesystem> and the need to explicitly set your Visual Studio 2022's use of the C++ language standard to at least C++17. Preferably C++20 since that is at this time the current standard.

https://cplusplus.com/forum/beginner/283668/#msg1228181

I'm going to remind you again:
LEARN to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either

We are trying to help you, but you need to make the effort of understanding and doing what we tell you.
Topic archived. No new replies allowed.