2011-04-23 45 views
0

我正在寻找一种方法来查找三个或更多的同名文件,但创建与另一个应用程序。然后,下一个操作会比较所有三个文件,以查看它们是否在同一日期创建,并最终将该日期与当前操作系统日期进行比较。找到三个相同名称的文件,但创建不同的应用程序

+1

你的意思是“与其他应用程序创建的”?例如,你的意思是说你有一个名为“Foo”的文件,由Word,Excel和记事本创建 - 因此文件扩展名为foo.doc,foo.xls和foo.txt? – Goyuix 2011-04-23 19:08:12

回答

1

作为了部分答案,因为我不知道你的意思有相同的名称...

,看文件是否是在同一天创建的,你可以比较每个参考的创建时间属性:

# 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 
相关问题