#include<windows.h>
#include<stdio.h>
#include<conio.h>
int main()
{
system("mkdir c:\\Imp");
getch();
}
How to check this Imp folder exists or not??
if exists not creating again??
#include<windows.h>
#include<stdio.h>
#include<conio.h>
int main()
{
system("mkdir c:\\Imp");
getch();
}
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:
Linux
#include <sys/stat.h>
mkdir (const char *path, mode_t mode);
in this case mode = O_CREAT. Function returns an int (0 on success)
Windows
#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...
I m not getting..it..
some more info or example code plz...
Since you appear to be on Windows, one way is to use GetFileAttributes(), see
http://msdn.microsoft.com/en-us/library/aa364944.aspx
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
http://msdn.microsoft.com/en-us/library/aa364944.aspx
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.
Example:
#include <windows.h>
#include <iostream>
[...]
if (!CreateDirectory("c:\\mydir", NULL))
std::cout << "Creating failed";
else
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. :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.