How to make directory using C++ on Windows

The function to create a new directory is not part of the C or C++ standard library. On Windows, this can be done using the CreateDirectory function call.

Using it is pretty easy:

#include <windows.h>

if (CreateDirectory("foo", NULL))
{
    // Directory created
}
else if (ERROR_ALREADY_EXISTS == GetLastError())
{
    // Directory already exists
}
else
{
    // Failed for some other reason
}

Tried with: Visual Studio 2013 and Windows 7 x64

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s