#include <iostream>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#define PP PATH_MAX+1
using namespace std;
class ls_Directory
{
private:
size_t size_path;
DIR *dir_function;
const char *directory_path;
char main_path[PP];
struct dirent *dir_entr;
public:
ls_Directory()
{
;
}
void read_Path(const char *directory)
{
directory_path=directory;
strncpy(main_path,directory_path,sizeof(main_path));
size_path=strlen(directory_path);
char end_char='/';
size_t temp_s=size_path-1;
if(main_path[temp_s]!=end_char)
{
main_path[size_path]=end_char;
main_path[temp_s+2]='\0';
++size_path;
}
dir_function=opendir(directory_path);
}
void write_Path()
{
while(((dir_entr=readdir(dir_function))&& dir_entr!=NULL))
{
char *temp;
strncpy(main_path+size_path,dir_entr->d_name,sizeof(main_path)-size_path);
cout<<temp<<" : "<<endl;
}
closedir(dir_function);
}
};
int main(int argc, char **argv)
{
string dir_unix[3]={"usr","lib","dev"};
ls_Directory *DIR_LINUX=new ls_Directory[3];
int i;
for(i=0;i<3;i++)
{
DIR_LINUX[i].read_Path(dir_unix[i].c_str());
DIR_LINUX[i].write_Path();
}
delete DIR_LINUX;
return 0;
}