CreateDirectory windows API usage in c++

久未见 提交于 2019-11-30 09:07:15

You will need admin access to create or delete a folder in C:\Users. Make sure that you are running the .exe as admin, to ensure you have these privileges. If you do not, then CreateDirectory will fail.

To get the error that is returned, use GetLastError. For a reference on the errors that may return, please take a look at the "Return value" section at

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363855%28v=vs.85%29.aspx

Also, the code you are looking for is

CreateDirectory ("C:\\Users\\morons", NULL);

As there needs to be a "\\" before "morons"

You need another backslash in there:

CreateDirectory ("C:\\Users\\morons", NULL);

Making a windows application cross-platform, was using CreateDirectory() c++17 standard now has std::filesystem::create_directories

#include<iostream>
#include <filesystem>

int main()
{
    std::filesystem::create_directories("C:\\newfolder\\morons");
}

Needs changes in makefile to -std=c++17 and updating to a GCC compiler that supports c++17.

In visual studio follow steps here to enable c++17

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!