0

How to make multiple directories with padded zeros from a single call to md (mkdir, New-Item)? From this thread, I see that I can use this command to pad regular directory names with trailing numbers:

0..10 | % { "dir_name{0:000}" -f $_ } | % { New-Item -ItemType directory -Name $_ }

~/directory/
dir_name000
dir_name001
dir_name002
dir_name003
dir_name004
dir_name005
dir_name006
dir_name007
dir_name008
dir_name009
dir_name010

...but is there a less verbose way with a single call to md?

Thanks to all the helpful input on this thread about finding a PowerShell equivalent to the 'nix command: mkdir dir_name{1..9} I see how this command:

0..10 | foreach $_{ New-Item -ItemType directory -Name $("dir_name" + $_) }

...can be done like this:

mkdir $(0..10 | %{"dir_name$_"})

...but how would I slug in the number padding into this syntax? Thank you!

MmmHmm
  • 768

1 Answers1

1

md -Name $_ $(0..10 | % { "dir_name{0:000}" -f $_ } )

~/directory/
dir_name000
dir_name001
dir_name002
...
dir_name008
dir_name009
dir_name010

MmmHmm
  • 768