bool Path::isFile() const
{
bool isFile = false;
_finddata_t data;
int descriptor = _findfirst(toString().c_str(), &data);
if (descriptor == -1)
isFile = false;
else if (!(data.attrib & _A_SUBDIR))
isFile = true;
else
isFile = false;
return isFile;
}
bool Path::isDirectory() const
{
bool isDirectory = false;
if (path_.c_str() == nullptr)
isDirectory = false;
else if (!exists())
isDirectory = false;
else {
_finddata_t data;
int descriptor = _findfirst(toString().c_str(), &data);
if (data.attrib & _A_SUBDIR) // data is directory?
isDirectory = true;
else if (exists() && !isFile()) // is root directory
isDirectory = true;
else
isDirectory = false;
}
return isDirectory;
}
// Создание объектов у Directory.cpp
std::string find = path_.toString();
find += "\\*";
_finddata_t* data = new _finddata_t;
int handle = _findfirst(find.c_str(), data);
int result = handle;
while (result != -1) {
if (strcmp(data->name, ".") == 0 || strcmp(data->name, "..") == 0) {
result = _findnext(handle, data);
continue;
}
Path internalObject(path_.toString() + '\\' + data->name);
if (internalObject.isFile())
childs_.push_back(new(std::nothrow) File(internalObject));
else
childs_.push_back(new(std::nothrow) Directory(internalObject));
result = _findnext(handle, data);
}