0

I am looking for a way to find three or more files of the same name but created with another application. Next action is then compare all three files to see if they were create on the same date and finaly compare that date against the current OS date.

4

1 回答 1

1

作为部分答案,因为我不确定你的意思是同名......

要查看文件是否在同一日期创建,您只需比较每个引用的 CreationTime 属性:

# Use Get-Item to retrieve FileInfo for two files
PS C:\> $a = Get-Item 'a.txt'
PS C:\> $b = Get-Item 'b.txt'
# Compare the DateTime field when they were created
PS C:\> $a.CreationDate -eq $b.CreationDate
False
# Compare just the 'Date' aspect of each file ignoring the time
PS C:\> $a.CreationDate.Date -eq $b.CreationDate.Date
True

您会注意到创建日期包含时间元素,因此除非它们确实完全相同,否则您可能无法获得预期的结果。要去除时间元素,您只需将 .Date 属性添加到任何 DateTime 字段。

要与操作系统日期和时间进行比较:

# store the OS Date and Time for easier reference
PS C:\> $now = [DateTime]::Now
PS C:\> $today = [DateTime]::Today
# Compare using the stored values
PS C:\> $a.CreationDate.Date -eq $now
False
PS C:\> $a.CreationDate.Date -eq $today
True
于 2011-04-23T19:19:53.773 回答