Portable way to check if directory exists [Windows/Linux, C]
stat() works on Linux., UNIX and Windows as well:
#include <sys/types.h>
#include <sys/stat.h>
struct stat info;
if( stat( pathname, &info ) != 0 )
printf( "cannot access %s\n", pathname );
else if( info.st_mode & S_IFDIR ) // S_ISDIR() doesn't exist on my windows
printf( "%s is a directory\n", pathname );
else
printf( "%s is no directory\n", pathname );
With C++17 you can use std::filesystem::is_directory
function (https://en.cppreference.com/w/cpp/filesystem/is_directory). It accepts a std::filesystem::path
object which can be constructed with a unicode path.