I'm trying to write a function that returns a list of all files on current folder and all of its sub folders. I wrote this code:
#include <iostream>
#include <dirent.h>
#include <cstring>
using namespace std;
int main() {
DIR* dir; dirent* pdir;
//From my workspace
dir=opendir(".");
while (pdir=readdir(dir)) {
if(/**********This pdir is a directory**********/) {
/**********RECURSIVE CALL SHOULD BE HERE**********/
cout<<pdir->d_name<<endl;
}
}
closedir(dir);
return 0;
}
I searched for it in google and I don't know how to:
- Check if the current
pdir
is directory - Go inside the directory and perform the recursive call on it
Meanwhile I have everything on main because I still don't know what arguments the recursive function should have.
Any hints?
See Question&Answers more detail:os