How to create a directory with C code (other than the method of forking and using mkdir) ? Is there anything like dirent.h? dirent.h only allows to read directories. (without using external library)
+4
A:
Use the mkdir function.
#include <sys/stat.h>
#include <sys/types.h>
int mkdir(const char *pathname, mode_t mode);
Douglas Leeder
2010-02-13 08:14:32
Please explain mode parameter
avd
2010-02-13 08:16:31
@lex: Why don't you just try and do some research for yourself?
dreamlax
2010-02-13 08:24:12
@lex please read the linked man page.
Douglas Leeder
2010-02-13 18:30:21
+4
A:
If you can use C++ (as suggested by the selected tags) and boost libraries, Boost filesystem can help you with the create_directory function.
If you don't want to have all boost libraries available in your project, you may download a tool called bcp to extract only the subset you need, in your case boost filesystem and its dependencies.
Benoît
2010-02-13 08:15:24
Boost is pure c++, which means you don't have to convert strings to char*. Boost filesystem lets you use "path" objects which are simple to use if you work with many related directories. There are more reasons to use it, but i haven't dug into it much.
Benoît
2010-02-13 08:32:06