int main()
  system("mkdir c:\\Imp"); 

How to check this Imp folder exists or not??
if exists not creating again??

I recommend not to use system(). What is someone makes a program called 'mkdir' that formats your HD? That would be quite a bummer.

Now for a solution:


#include <sys/stat.h>

mkdir (const char *path, mode_t mode);

in this case mode = O_CREAT. Function returns an int (0 on success)


#include <windows.h>

CreateDirectory (char *DirName, SECURITY_ATTRIBUTES Attribs);

If the function succeeds returns non-zero else NULL.

I m not getting..it..

some more info or example code plz...

What aren't you 'getting'?
What OS are you using? The code you posted is a strange blend of linux/windows...

Since you appear to be on Windows,

Because he included <windows.h> I sort of agree with you, but 'mkdir' is pure linux, so that's why I asked to make sure :)

one way is to use GetFileAttributes(), see

To check if the dir exists: yes. But the OP wants to create a dir, so CreateDirectory (char *DirName, SECURITY_ATTRIBUTES Attribs); would be the way to go.


#include <windows.h>
#include <iostream>
if (!CreateDirectory("c:\\mydir", NULL)) 
   std::cout << "Creating failed"; 
    std::cout << "Success!";

but 'mkdir' is pure linux

Nope, Windows recognizes mkdir as well ;)

Nope, Windows recognizes mkdir as well ;)

You're right! Never knew that...
I'm from the Dos-age: md this and rd that. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.