Hi,

I wrote this recursive function to 'pretty print' directory listings but for some reason it only recurses down through one directory?

Code:
 
void recursive_dir(DIR* directory,int tabs){ 
   
  if(!(directory)) { 
    error("Directory is not accesible"); 
    return; 
  } 
   
  struct dirent *dip; 
 
  while(( dip = readdir( directory ))){ 
    if(!strcmp(dip->d_name, ".") || !strcmp(dip->d_name, "..")) 
      continue; 
     
    DIR* d = opendir(dip->d_name); 
    if(d != NULL){ 
      cout << "|-**"; 
      for(int i=0;i<tabs;i++)  // Print out the tabs 
	cout << "---"; 
      cout << dip->d_name << "\n"; 
      recursive_dir(d,tabs+1); 
      closedir( d ); 
      continue; 
    } 
    
    for(int i=0;i<tabs;i++)  // Print out the tabs 
      cout << "   "; 
     
    cout << "|- " << dip->d_name << "\n";   
  } 
   
  return; 
}
--------------------------------------------------------------------------------


Think I may have used opendir() wrong but cant see where,

thanks for any help

Brif

ps I also posted this on the c board but was asked to put it here, sorry about that.