Make a directory using C++ for windows

If you want to create a folder in windows operating system using c++/cpp language, there is an easy way to make a folder (or directory). You can do it just including the <windows.h> header file. To make a folder in C:\ drive named "deadman"

#include<windows.h>

int main(){
   CreateDirectory ("C:\\deadman", NULL);
   return 0;
}

If you want to delete a fodler from the C:\ directory.

#include<windows.h>

int main(){
   RemoveDirectory("C:\\deadman");
   return 0;
}

Also you can use the system command from c++ to create or delete a fodler. for example
system("mkdir c:\\deadman");

Comments

Anonymous said…
The boost library set (boost.org) is a really usefull thing.

A part of this set can be used to use file system : list files, parse directories... and create directories.

This part is called boost::filesystem.

----------------------------
#include "boost/filesystem.hpp"
boost::filesystem::create_directory( "C:\\deadman" );
----------------------------

boost::filesystem can be used on other OS. "windows.h" can't.

Boost is a really well designed, that can teach alot.

Unfortunately, filesystem is one of the hardest part of boost to install, because you'l have to compile it before (almost all other libraries are only headers).

But it worth it.
Sairaj said…
Hey thanks
was looking for similar answer
I want some link for c++ coding windows gui enviroment