1
我有一个非常简单的ASP.NET MVC应用程序的目录结构,样本如下:忽略只在根目录下的文件GET-ChildItem
root/
----- views/
---------- index.cshtml
---------- web.config
----- scripts/
---------- main.js
---------- plugin.js
----- web.config
鉴于此目录结构,我有一个小PowerShell脚本是复制[sourceDir]
中的所有内容,忽略一些文件,并将其复制到[targetDir]
。
我在使用Get-ChildItem
cmdlet复制[sourceDir]
中的所有内容的第一步时遇到问题。这里是我的示例脚本(编辑为简洁起见):
Get-ChildItem [sourceDir] -Recurse -Exclude web.config | Copy-Item -Destination [targetDir]
的问题是,-Exclude
参数排除在根web.config中,并在视图目录下的Web.config。从技术上讲,它忽略了每个web.config;不过,我只想忽略根目录中的文件。
是否可以只通过Get-ChildItem
忽略根目录下的web.config?如果不是,我应该使用哪个cmdlet?
解决方案
至于建议,放弃了当LINQ的条款是正确的解决方案的-Exclude参数。其实我有忽略文件的数组,所以我用了-NotIn
操盘的-NotMatch
的,示例脚本:
Get-ChildItem [sourceDir] -Recurse |
Where { $_.FullName -NotIn $_filesToIgnore } |
Copy-Item -Destination [targetDir]
完美。我的Linq-in-Powershell-fu很弱,但这正是我所需要的。从技术上讲,我有一组文件要忽略,所以我用-NotIn替换了-NotMatch。 –