Can any one tell me how to create a directory in c++ and C language. I have tried this but not working :Code:system ("md directory");
Can any one tell me how to create a directory in c++ and C language. I have tried this but not working :Code:system ("md directory");
There are mkdir and rmdir functions that should work in both environments (in Windows. The mkdir (make directory) command in the Unix, DOS, OS/2 and Microsoft Windows operating systems is used to make a new directory. They have an _ prefix that you can omit by a "define mkdir _mkdir" proprocessor statement.Code:#include <sys/stat.h> mkdir (const char *path, mode_t mode);
Try the following program to create directory in C++ :
Code:#include<iostream.h> #include<sys/stat.h> #include<sys/types.h> using namespace std; main() { if(mkdir("path",0777)==-1)//creating a directory { cerr<<"Error : "<<strerror(errno)<<endl; exit(1); } }
System("mkdir -p /tmp/a/b/c") -p: will also create all directories leading up to the given directory that do not exist already. You can use or SHCreateDirectory or SHCreateDirectoryEx API ([To set security attributes on a new folder, use SHCreateDirectoryEx) to create Intermediate directories if they're not existing.
Bookmarks