Kubek
Kubek

Reputation: 1

Various lenght of paths using new-item in powershell

So,I will try to explain this as much as I can. Ive tried to create a simple code which will create various folders regarding 3 parameters

  1. where folders should be made
  2. how deep should the path be....hope the translation is correct
  3. how many folders are supposed to be created in the end folder

I can say that I have the last step...but I dont have idea how to create the rest. Please see the notepad description below..and also what Ive done so far.

description

param (
$path = "C:\test",
$M = 5,
$N = 2)

for ($i = 0; $i -lt $M; $i++)
{        $name = (New-Guid).guid
     New-Item -ItemType Directory -path $path -name $name -force 
}

Thanks for the ideas !

Upvotes: 0

Views: 40

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174515

You never change the value of $path, so all the new directories will be created under the same root folder.

param (
  $path = "C:\test",
  $M = 5,
  $N = 2
)

$folder = Get-Item $path

for ($i = 0; $i -lt $M; $i++)
{
     $name = (New-Guid).Guid
     $folder = New-Item -ItemType Directory -LiteralPath $folder.FullName -Name $name -Force 
}

# create your $N folders in the final (current) $folder here

Upvotes: 0

Related Questions