简体   繁体   English

在 Powershell 中使用 Select-String -NotMatch

[英]Using Select-String -NotMatch in Powershell

I'm trying to find .nfo files that aren't XML.我正在尝试查找不是 XML 的 .nfo 文件。 It seems to mostly work, but some of the files are XML and are still being listed.它似乎主要工作,但一些文件是 XML 并且仍在列出。 One example has this for the first line:一个例子的第一行是这样的:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

Here is my code.这是我的代码。 I'm not sure what I am doing wrong.我不确定我做错了什么。

Get-ChildItem "c:\*.nfo" -recurse | ForEach-Object {
    if (Get-Content -LiteralPath $_ -First 1 | Select-String -Pattern 'xml' -NotMatch) 
    {
        Write-Output $_.Fullname
    }
}

I don't care if they are properly formatted XML files so I am just using the first line to test.我不在乎它们是否格式正确的 XML 文件,所以我只是使用第一行来测试。

尝试这个

Get-ChildItem "c:\*.nfo" -recurse | Where-Object{(Get-Content $_ -First 1) -notmatch 'xml'}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM