C++ - Creating folder method

Posted by Matthew on Stack Overflow See other posts from Stack Overflow or by Matthew
Published on 2012-11-07T10:50:11Z Indexed on 2012/11/07 11:00 UTC
Read the original article Hit count: 163

Filed under:
|
|
|
|

I have the following method in C++:

void create_folder(LPCWSTR full_folder) //Method to create folder in case it does not exist
{
    if(!CreateDirectory(full_folder,attr)) //Checking whether the folder already exists
    {
        switch (GetLastError())
        {
            case ERROR_ALREADY_EXISTS:
                printf("The folder already exists!\n\n");
                break;

            case NULL:
                printf("The folder does not exist!\n\n");
                printf("The folder was created successfully!\n\n");
                break;
        }
    }
}

In case the folder already exists, the correct message is displayed on the screen. However, if the folder does NOT exist, nothing is displayed on the screen, that is, the part identified by case NULL is not executed. How can I solve this problem?

In other words, how can I get the code after the case NULL to run if the folder does not exist?

© Stack Overflow or respective owner

Related posts about c++

Related posts about winapi