如何使用Get-ChildItem -exclude排除多个文件夹? [英] How can I exclude multiple folders using Get-ChildItem -exclude?

查看:954
本文介绍了如何使用Get-ChildItem -exclude排除多个文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为我们的Pro / Engineer CAD系统生成一个配置文件。我需要从我们服务器上的特定驱动器的文件夹的递归列表。但是我需要EXCLUDE包含ARCHIVE的任何文件夹,其中包括各种不同的情况。



我已经写了以下工作,除了它不排除文件夹!

  $ folder =T:\Drawings\Design\ *
$ raw_txt =T: \Design Projects\Design_Admin\PowerShell\raw.txt
$ search_pro =T:\Design Projects\Design_Admin\PowerShell\search.pro
$ archive = *存档*,*存档*,* ARCHIVE *

Get-ChildItem -Path $ folder -Exclude $ archive -Recurse |其中{$ _。属性-match'Directory'} | ForEach-Object {$ _。FullName}> $ search_pro


解决方案

我会这样做: / p>

  Get-ChildItem -Path $ folder -r | 
? {$ _。PsIsContainer -and $ _。FullName -notmatch'archive'}


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 EXCLUDE any folder with 'ARCHIVE' in it including the various different cases.

I've written the following which works except it doesn't exclude the folders !!

$folder = "T:\Drawings\Design\*"
$raw_txt = "T:\Design Projects\Design_Admin\PowerShell\raw.txt"
$search_pro = "T:\Design Projects\Design_Admin\PowerShell\search.pro"
$archive = *archive*,*Archive*,*ARCHIVE*

Get-ChildItem -Path $folder -Exclude $archive -Recurse  | where {$_.Attributes -match 'Directory'}  | ForEach-Object {$_.FullName} > $search_pro   

解决方案

I'd do it like this:

Get-ChildItem -Path $folder -r  | 
          ? { $_.PsIsContainer -and $_.FullName -notmatch 'archive' }

这篇关于如何使用Get-ChildItem -exclude排除多个文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆