PowerShell equivalent of LINQ Any()?

前端 未结 11 665
灰色年华
灰色年华 2020-12-01 03:29

I would like to find all directories at the top level from the location of the script that are stored in subversion.

In C# it would be something like this

         


        
11条回答
  •  遥遥无期
    2020-12-01 03:57

    My approach now was:

    gci -r -force `
        | ? { $_.PSIsContainer -and $_.Name -match "^[._]svn$" } `
        | select Parent -Unique
    

    The reason why

    select-object {$_.Directory}
    

    doesn't return anything useful is that there is no such property on a DirectoryInfo object. At least not in my PowerShell.


    To elaborate on your own answer: PowerShell can treat most non-empty collections as $true, so you can simply do:

    $svnDirs = gci `
        | ? {$_.PsIsContainer} `
        | ? {
            gci $_.Name -Force `
                | ? {$_.PSIsContainer -and ($_.Name -eq "_svn" -or $_.Name -eq ".svn") }
            }
    

提交回复
热议问题