继续进行中
Continue in pipeline
定义路径时我想做很多事情,包括如果文件夹已经存在则跳过这是我目前的尝试:
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
然而 Continue
让我完全脱离了循环。我想这不是一个真正的循环想知道是否有更好的方法来实现上述目标?
第二次尝试 - 分手
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
}
}
我不明白为什么在您给出的场景中需要 continue
。对于第二部分,您可以这样做:
foreach ($directory in $directories)
{
if($copyTo -match $directory.Name)
{
# checking if directory already exists
$alreadyExists = Test-Path $copyTo
if(!$alreadyExists){
New-Item -ItemType Directory -Path $copyTo -Force
}
}else{
$path = Join-Path $copyTo $directory.Name
New-Item -ItemType Directory -Path $path -Force
}
}
定义路径时我想做很多事情,包括如果文件夹已经存在则跳过这是我目前的尝试:
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
然而 Continue
让我完全脱离了循环。我想这不是一个真正的循环想知道是否有更好的方法来实现上述目标?
第二次尝试 - 分手
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
}
}
我不明白为什么在您给出的场景中需要 continue
。对于第二部分,您可以这样做:
foreach ($directory in $directories)
{
if($copyTo -match $directory.Name)
{
# checking if directory already exists
$alreadyExists = Test-Path $copyTo
if(!$alreadyExists){
New-Item -ItemType Directory -Path $copyTo -Force
}
}else{
$path = Join-Path $copyTo $directory.Name
New-Item -ItemType Directory -Path $path -Force
}
}