我正在读取两个MS Word文件,需要比较docx属性。
我得到了每个变量的正确输出,但是一旦我比较它们,它就会抛出以下错误。
知道为什么吗?
Major Minor Build Revision
----- ----- ----- --------
1 0 -1 -1
1 1 -1 -1
无法将"1.0"与"1.1"进行比较。错误:"无法将类型为"系统对象[]"的"系统对象[]"值转换为 键入"系统版本"。 at C:\Users\Sebastian\Documents\IT Projects\Saberwal\Groups - Advanced.ps1:76 char:6 + if ($CurrentVersion -lt $NewVersion) {Write-Output "New is bigger"} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 类别信息 : 无效操作: (:) [], 运行时异常 + 完全限定错误 ID:比较失败
法典:
$CurrentVersion = Check-Version $CurrentSignaturePath $CurrentSignatureFile
$NewVersion = Check-Version $NewSignaturePath $NewSignatureFile
Write-Output $CurrentVersion
Write-Output $NewVersion
if ($CurrentVersion -lt $NewVersion) { Write-Output "New is bigger" }
好的,找到了一种方法。
[version]$CurrentVersion = [string]$CurrentVersion
[version]$NewVersion = [string]$NewVersion
谢谢大家
试试这个:
[Version] $CurrentVersion = Check-Version $CurrentSignaturePath
[Version] $CurrentSignatureFile $NewVersion = Check-Version $NewSignaturePath $NewSignatureFile
如果只是尝试将两个版本与-lt
进行比较,它工作正常。