Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Looping through subfolders with [foreach]

$
0
0

What I have now:

## Create variables for subfolders $sub = @("Lectures", "Labs", "Assignments", "Scripts") ## Loop through collection to create subfolders foreach ($item in $sub) {New-Item -ItemType directory} 

Initially, I tried

## Create variables for subfolders $sub1 = "Lectures" $sub2 = "Labs" $sub3 = "Assignments" $sub4 = "Scripts" 

But this way, I cannot use a foreach loop. Im trying to create the subfolders, but it asks me for path, (ie what I want to name the folders) with each {New-Item -ItemType directory}. I already specified the names, I want it to go through $sub variable

Thanks!

submitted by /u/chy_vak
[link] [comments]

The post Looping through subfolders with [foreach] appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images