How can I exclude multiple folders using Get-ChildItem -exclude?

前端 未结 12 957
星月不相逢
星月不相逢 2020-11-27 16:19

I need to generate a configuration file for our Pro/Engineer CAD system. I need a recursive list of the folders from a particular drive on our server. However I need to EXCL

12条回答
  •  一向
    一向 (楼主)
    2020-11-27 17:11

    The simplest short form to me is something like:

    #find web forms in my project except in compilation directories
    (gci -recurse -path *.aspx,*.ascx).fullname -inotmatch '\\obj\\|\\bin\\'
    

    And if you need more complex logic then use a filter:

      filter Filter-DirectoryBySomeLogic{
      
          param(
          [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
          $fsObject,
          [switch]$exclude
          )
              
          if($fsObject -is [System.IO.DirectoryInfo])
          {
              $additional_logic = $true ### replace additional logic here
      
              if($additional_logic){
                  if(!$exclude){ return $fsObject }
              }
              elseif($exclude){ return $fsObject }
          }
              
      }
      
      gci -Directory -Recurse | Filter-DirectoryBySomeLogic | ....
    

提交回复
热议问题