mkdir ("dir1/{dir1-1,dir1-2}",0755,TRUE);
This command creates the folder dir1 with a single subfolder called '{dir1-1,dir1-2}' instead of creating dir1-1 and dir1-2 as two subfolders for dir1.
Any idea how to get this to work from a single mkdir command as above?
PHP does not support brace expansion in the same way as the shell does. If you want to create multiple directories, you will have to call mkdir()
multiple times, and you can easily do this by looping.
You can pass TRUE
as the third argument to mkdir()
- this means that all directories back up the tree will also be created if they do not exist and the parent is writable. You can safely pass TRUE
to all calls when operating in a loop, the first iteration for a given directory will create it, subsequent calls will have no adverse effect.
For example:
$toCreate = array(
'dir1/dir1-1',
'dir1/dir1-2'
);
$permissions = 0755;
foreach ($toCreate as $dir) {
mkdir($dir, $permissions, TRUE);
}