#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <iostream.h>
#include <string>
#include <stdlib.h>
#include <string>
#include <unistd.h>
using namespace std;
class DiskUtil4 {
private:
DIR *_dir;
struct dirent *_dirpointer;
struct stat _filesize;
unsigned long _size;
int _locStatus;
public:
DiskUtil4();
~DiskUtil4();
int GetUsedDirectorySpace(string path_, unsigned long& filesize_) {
if((_dir=opendir(path_.c_str())) == 0) {
cout<<"Error while opening path"<<endl;
}
while((_dirpointer = readdir(_dir)) != 0) {
if(stat((char*)_dirpointer->d_name, &_filesize) == -1) {
return -1;
}
else if((_dirpointer->d_name != ".") || (_dirpointer->d_name != "..")) {
if(_filesize.st_mode & S_IFDIR) {
GetUsedDirectorySpace(_dirpointer->d_name, filesize_);
}
else if(_filesize.st_mode & S_IFREG) {
_size = _filesize.st_size;
filesize_ = filesize_ + _size;
cout<<"Filename: "<<_dirpointer->d_name<<endl;
cout<<"Filesize: "<<_size<<endl;
}
}
else {
filesize_ = filesize_ + _filesize.st_blksize;
}
}
closedir(_dir);
}
};
DiskUtil4:
iskUtil4() {
unsigned long _size=0;
}
DiskUtil4::~DiskUtil4() {
}
int main() {
DiskUtil4 probe;
string path_="/home/a121653/Projekte";
unsigned long test=0;
probe.GetUsedDirectorySpace(path_.c_str(),test);
cout<<"Directory Size: "<<test/1024<<"KB"<<endl;
}