mkdir Windows vs Linux

MindlessMaik picture MindlessMaik · Apr 27, 2012 · Viewed 25.3k times · Source

I have a problem while porting a Linux tool to Windows. I am using MinGW on a Windows system. I have a class which handles all the in/output and within is this line:

mkdir(strPath.c_str(), 0777); // works on Linux but not on Windows and when it is changed to
_mkdir(strPath.c_str()); // it works on Windows but not on Linux

Any ideas what I can do, so that it works on both systems?

Answer

gcochard picture gcochard · Apr 27, 2012
#if defined(_WIN32)
_mkdir(strPath.c_str());
#else 
mkdir(strPath.c_str(), 0777); // notice that 777 is different than 0777
#endif