Search code examples
bashpowershellpowershell-3.0powershell-4.0brace-expansion

create multiple subdirectory using mkdir in powershell


Is there a way I can do this in ms powershell? (w/o scripting)

mkdir a\b\c\d{a,b,c,d}

I want to make multiple subdirectories at once just like in bash but when i run it in powershell it gives me this error :

At line:1 char:17
+ mkdir a\b\c\d{a,b,c,d}
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingArgument**

I had tried all of the following:

mkdir a\b\c\d\{a b c d}
mkdir a\b\c\d\a,b,c,d}
mkdir a\b\c\d\[a,b,c,d]

Solution

  • Try this:

    "a","b","c","d" | % { mkdir "a\b\c\d\$_" }
    

    or

    echo a,b,c,d | % { mkdir "a\b\c\d\$_" }
    

    See: Powershell equivalent of Bash Brace Expansion for generating lists/arrays