#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
using namespace std;
class Directory
{
private:
char *name_of_path;
char *temp;
char end;
size_t size_path;
DIR *directory;
struct dirent *my_entry;
char base_path[PATH_MAX];
public:
Directory(char *name);
bool is_Socket();
bool is_Normal();
bool is_Fifo();
bool is_Directory();
bool is_Block();
bool is_Char();
char *info_Path();
void directory_Info();
};
Directory::Directory(char *name)
{
name_of_path=name;
end='/';
directory=opendir(name_of_path);
}
bool Directory::is_Socket()
{
struct stat info;
lstat(name_of_path,&info);
if(S_ISSOCK(info.st_mode))
return true;
else
return false;
}
bool Directory::is_Normal()
{
struct stat info;
lstat(name_of_path,&info);
if(S_ISREG(info.st_mode))
return true;
else
return false;
}
bool Directory::is_Fifo()
{
struct stat info;
lstat(name_of_path,&info);
if(S_ISFIFO(info.st_mode))
return true;
else
return false;
}
bool Directory::is_Directory()
{
struct stat info;
lstat(name_of_path,&info);
if(S_ISDIR(info.st_mode))
return true;
else
return false;
}
bool Directory::is_Block()
{
struct stat info;
lstat(name_of_path,&info);
if(S_ISBLK(info.st_mode))
return true;
else
return false;
}
bool Directory::is_Char()
{
struct stat info;
lstat(name_of_path,&info);
if(S_ISCHR(info.st_mode))
return true;
else
return false;
}
char *Directory::info_Path()
{
if (is_Char())
{
return "dev char";
}
else if (is_Block())
{
return "dev blocket";
}
else if (is_Directory())
{
return "directory";
}
else if (is_Fifo())
{
return "fifo";
}
else if (is_Normal())
{
return "normal file";
}
else
{
"another";
}
}
void Directory::directory_Info()
{
strncpy(base_path,name_of_path,sizeof(base_path));
size_path=strlen(name_of_path);
if(base_path[size_path-1]!=end)
{
base_path[size_path]=end;
base_path[size_path+1]='\0';
++size_path;
}
do
{
strncpy(base_path+size_path,my_entry->d_name,sizeof(base_path)-size_path);
temp=info_Path();
cout<<temp<<" - "<<base_path<<endl;
}while((my_entry=readdir(directory))!=NULL);
closedir(directory);
}
Brak komentarzy:
Prześlij komentarz