I'm trying to find the type of file a path is. I have this for Linux::
pathType CFilesystem::findPathType(const string& path) const
{
struct stat info;
int status = stat(path.c_str(), &info);
if(status == -1)
{
switch(errno)
{
case ENOENT: // A component of the path does not exist.
return pathType::none;
default:
return pathType::unknown;
}
}
if(S_ISDIR(info.st_mode))
{
return pathType::directory;
}
if(S_ISREG(info.st_mode))
{
return pathType::file;
}
return pathType::unknown;
}
But I'm not sure how to do the same for Windows. _stat doesn't seem to work (it says a file doesn't exist, even know I'm POSITIVE it exists. After all, the programming is running from it.
In windows, I think the function you are looking for is GetFileAttributesEx
You can also use the regular _stat function on windows as well though. Are you including sys/types.h and sys/stat.h?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With