When defining the path I want to do numerous things, including skip if the folder already exists this is my attempt so far:
Get-ChildItem -Path $featureDirectory -Recurse | Where-Object {$_.PSIsContainer -eq $true} |
New-Item -ItemType Directory -Path {
Write-Host "Checking if directory needed for " $_.Name
# checking to see path is part of Copy To directory
if($copyTo -Match $_.Name)
{
# checking if directory already exists
$alreadyExists = Test-Path $copyTo
if($alreadyExists)
{
Continue
}
Write-Host "Creating full directory path for directory for: " $copyTo
$copyTo
}else{
Write-Host "Creating directory for: " $copyTo $_.Name
Join-Path $copyTo $_.Name
}
} -Force
However Continue
breaks me out of the loop entirely. I guess it's not a true loop was wondering if there is a better way to achieve the above or not?
Second Attempt - Breaking it up
foreach ($directory in $directories)
{
if($copyTo -match $directory.Name)
{
# checking if directory already exists
$alreadyExists = Test-Path $copyTo
if($alreadyExists)
{
continue
}else{
New-Item -ItemType Directory -Path $copyTo -Force
}
}else{
$path = Join-Path $copyTo $directory.Name
New-Item -ItemType Directory -Path $path -Force
}
}