loops - Continue in pipeline -


when defining path want numerous things, including skip if folder exists attempt far:

get-childitem -path $featuredirectory -recurse | where-object {$_.psiscontainer -eq $true} |      new-item -itemtype directory -path {         write-host "checking if directory needed " $_.name         # checking see path part of copy directory         if($copyto -match $_.name)         {             # checking if directory exists             $alreadyexists = test-path $copyto             if($alreadyexists)             {                 continue             }             write-host "creating full directory path directory for: " $copyto             $copyto         }else{             write-host "creating directory for: " $copyto $_.name             join-path $copyto $_.name          }      } -force 

however continue breaks me out of loop entirely. guess it's not true loop wondering if there better way achieve above or not?

second attempt - breaking up

foreach ($directory in $directories) {     if($copyto -match $directory.name)     {         # checking if directory 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     } } 

i fail understand why need continue in scenario you've given. taking second part, do:

foreach ($directory in $directories) {     if($copyto -match $directory.name)     {         # checking if directory 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     } } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -