比较 2 个文件的最后修改

Comparing last Modified from 2 Files

我正在尝试执行一个 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

这将为您提供您所追求的逻辑。但是,$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"
}