gpt4 book ai didi

powershell - 检查文件的前 n 个字节是否在 Powershell 中是特定的

转载 作者:行者123 更新时间:2023-12-01 23:05:44 24 4
gpt4 key购买 nike

如何将文件中的字节与值的文字数组进行比较?

$path = "C:\BinaryFile.bin"
$bytes = Get-Content -LiteralPath $path -Encoding byte -TotalCount 4 -ReadCount 4
if ($bytes -eq [0 1 2 3]) { # How to compare to expected bytes?
Write-Output "OK: $bytes"
}

最佳答案

也许比较对象。没有输出意味着相等。 Syncwindow 0 以获得准确的顺序。

$path = 'file'
[byte[]](0..3) | set-content $path -Encoding Byte
$bytes = Get-Content $path -Encoding byte -TotalCount 4
if (! (compare-object $bytes 0,1,2,3 -syncwindow 0)) {
"OK: $bytes"
}

或者做一个字符串比较:

if ("0 1 2 3" -eq $bytes) {
"OK: $bytes"
}

关于powershell - 检查文件的前 n 个字节是否在 Powershell 中是特定的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70927857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com