Friday, March 21, 2008

Make a directory using C++ for windows

Share at Facebook

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


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

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


int main(){
   return 0;

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


Feriaman said...

The boost library set ( 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