Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create multiple directories from a single full path in C#?

People also ask

How to make multiple directories at once in terminal?

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.

How to create a folder with full permissions in Linux?

To create a directory with specific permissions, invoke the mkdir commanf with the -m ( -mode ) option. The syntax for assigning permissions is the same as with the chmod command. When the -m option is not used, the newly created directories usually have either 775 or 755 permissions, depending on the umask value.

How do I create a directory in CPP?

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.


I would call Directory.CreateDirectory(@"C:\dir0\dir1\dir2\dir3\dir4\").

Contrary to popular belief, Directory.CreateDirectory will automatically create whichever parent directories do not exist.
In MSDN's words, Creates all directories and subdirectories as specified by path.

If the entire path already exists, it will do nothing. (It won't throw an exception)


Create directories from complete filepath

private String EvaluatePath(String path){

    try
    {
        String folder = Path.GetDirectoryName(path);
        if (!Directory.Exists(folder))
        {
            // Try to create the directory.
            DirectoryInfo di = Directory.CreateDirectory(folder);
        }
    }
    catch (IOException ioex)
    {
        Console.WriteLine(ioex.Message);
        return "";
    }
    return path;
}