I am new to programming.I want to access all the directories and sub-directories from default installed directory,but it is failing in traversing the folder, here i am passing path to constant char.Below is the code
using namespace std;
int reading(const char *d_path)
{
cout<<"In Reading"<<endl;
/*bfs::path pathSource("c:\\Program Files\\");*/
struct stat info; //
DIR *dir;
struct dirent *ent;
dir= opendir (d_path);
cout<<dir<<endl;
if ((dir = opendir (d_path)) != NULL)
{
cout<<"in IF"<<endl;
while ((ent = readdir (dir)) != NULL)
{
if (ent->d_name[0] != NULL)
{
cout<<"New"<<endl;
string path = string (d_path) + string(ent->d_name) + '\\' ;
cout<< "Entry = "<<path<<endl;
stat (path,&info);
if(S_ISDIR(info.st_mode))
{
reading(path);
}
}
}
closedir (dir);
}
/* print all the files and directories within directory */
else
{
/* could not open directory */
perror ("");
}
return 0;
}