1

I need to create a folder and subfolder with name from E1 to E10 and inside each folder have 10 more folders, how do i do that in PowerShell ISE?

1 Answer 1

2

The following creates subfolders E1 through E10, and, inside each, subfolders F1 through F10:

# Creates subdirectories and returns info objects about them.
# -Force means that no error is reported for preexisting subdirs.
# Use $null = New-Item ... to suppress output.
New-Item -Type Directory -Force `
         -Path (1..10 -replace '^', 'E').ForEach({ 1..10 -replace '^', "$_\F" })

Note:

  • -replace '^', '...' is a simple way to prepend text to each input array element (each of the sequence numbers created with the .., the range operator, in this case).
  • -replace '$', '...' would append.
  • To insert the input in an arbitrary position, use ^.* to match the entire input and $& to refer to it in the replacemenent text; e.g.
    -replace '^.*', 'Before-$&-After'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.