Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 查找三个同名但使用不同应用程序创建的文件_Powershell_Powershell 1.0 - Fatal编程技术网

Powershell 查找三个同名但使用不同应用程序创建的文件

Powershell 查找三个同名但使用不同应用程序创建的文件,powershell,powershell-1.0,Powershell,Powershell 1.0,我正在寻找一种方法,以找到三个或更多的文件相同的名称,但与另一个应用程序创建。下一步是比较所有三个文件,看看它们是否是在同一日期创建的,并最终将该日期与当前操作系统日期进行比较。作为部分答案,因为我不确定您的意思是同名 要查看文件是否在同一日期创建,只需比较每个引用的CreationTime属性: # Use Get-Item to retrieve FileInfo for two files PS C:\> $a = Get-Item 'a.txt' PS C:\> $b = G

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

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

要查看文件是否在同一日期创建,只需比较每个引用的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
您会注意到创建日期包含一个时间元素,因此除非它们确实完全相同,否则您可能无法获得预期的结果。要去掉时间元素,只需在任何DateTime字段中添加.Date属性

要与操作系统日期和时间进行比较,请执行以下操作:

# 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
“使用其他应用程序创建”是什么意思?例如,您的意思是说您有一个名为“Foo”的文件,它是由Word、Excel和记事本创建的,因此具有文件扩展名Foo.doc、Foo.xls和Foo.txt?