我正在尝试执行IF函数,以比较2个文件的上次修改日期。
这样的事情。
#include <Date.au3>
#include <MsgBoxConstants.au3>
$FileTime1 = FileGetTime("C:folder\file1.exe", 0, 1)
$FileTime2 = FileGetTime("C:\folder\file2.exe", 0, 1)
If $FileTime1=$FileTime2 Then
MsgBox(0, "TITLE", "EQUAL", 10)
Else
MsgBox(0, "TITLE", "DIFFERENT", 10)
EndIf
答案 0 :(得分:1)
这将为您提供所要遵循的逻辑。但是,$FileTime
变量将显示为Friday, 14 December 2018 12:29:46 PM
,因此如果它们在LastWriteTime
中相差1秒,则它们将不同。
$FileTime1 = (Get-Item 'C:folder\file1.exe').LastWriteTime
$FileTime2 = (Get-Item 'C:folder\file2.exe').LastWriteTime
if($FileTime1 -eq $FileTime2) {
Write-Host "Equal"
} Else {
Write-Host "Different"
}
如果您要比较两个文件以查看它们是否相同,建议使用Get-FileHash
$FileHash1 = (Get-FileHash 'C:folder\file1.exe').Hash
$FileHash2 = (Get-FileHash 'C:folder\file2.exe').Hash
if($FileHash1 -eq $FileHash2) {
Write-Host "Equal"
} Else {
Write-Host "Different"
}