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
Post a Comment