what is a convenient way to create a directory when a path like this is given: "\server\foo\bar\"
note that the intermediate directories may not exist.
CreateDirectory and mkdir only seem to create the last part of a directory and give an error otherwise.
the platform is windows, MSVC compiler.
thanks!
Problem: Write a C/C++ program to create a folder in a specific directory path. This task can be accomplished by using the mkdir() function. Directories are created with this function. (There is also a shell command mkdir which does the same thing).
The mkdir function creates a new, empty directory with name filename . The argument mode specifies the file permissions for the new directory file. See The Mode Bits for Access Permission, for more information about this. Write permission is denied for the parent directory in which the new directory is to be added.
You can create directories one by one with mkdir, but this can be time-consuming. To avoid that, you can run a single mkdir command to create multiple directories at once. To do so, use the curly brackets {} with mkdir and state the directory names, separated by a comma.
If you can use an external library, I'd look at boost::filesystem
#include <boost/filesystem.hpp>
namespace fs=boost::filesystem;
int main(int argc, char** argv)
{
fs::create_directories("/some/path");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With