Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to make directory using C++ on Windows

📅 2014-Aug-07 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ createdirectory ⬩ 📚 Archive

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


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧