powershell - 在 PowerShell 中获取具有 .md5 对应项的所有文件的列表

标签 powershell

我正在编写一个 PowerShell 脚本,其中需要获取具有互补 .md5 文件的文件列表。例如,如果我有一个文件名 abc.txt,如果同一目录中存在名为 abc.txt.md5 的文件,我只想将其添加到列表中.

这是我的尝试,但没有成功。我不知道为什么?

$DirectoryToScan = ".\SomePath"
$Files = Get-ChildItem $DirectoryToScan -Recurse |
    Where-Object { !$_.PSIsContainer } |
    Where-Object { $_.Name -notmatch ".*\.md5" } |
    Where-Object { Test-Path "$($_.FullName).md5" }

没有最后一个 Where-Object 子句,它可以正常工作。

最佳答案

你所给予的对我有用,但你可以尝试做这样的事情:

gci $DirectoryToScan -recurse -exclude "*.md5" | ?{ -not $_.PsIsContainer } | 
      ?{ test-path ($_.fullname + ".md5") } 

关于powershell - 在 PowerShell 中获取具有 .md5 对应项的所有文件的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9691151/

相关文章:

c# - 如何在 docker 容器内运行此 PowerShell 脚本?

windows - 运行带有 Git 命令的远程 PowerShell 脚本会导致 NativeCommandError

PowerShell 脚本将文件(但不包括子文件夹)复制到 SFTP,并在完成后移动到子文件夹

powershell - 根据文件名子字符串创建文件夹

Facebook 通过 PowerShell 实现自动化?

powershell - 需要来自 Invoke-WebRequest 输出的特定字符串行

powershell - 如何保持 powershell 脚本 24/7 运行

windows - 用户和本地组使用 Powershell 报告?

powershell - 从日志文件中选择主机名

xml - 解析 XML 并输出到 Excel