-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathFind-NewestFile.ps1
More file actions
35 lines (27 loc) · 928 Bytes
/
Find-NewestFile.ps1
File metadata and controls
35 lines (27 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<#
.SYNOPSIS
Finds the most recent file.
.INPUTS
System.IO.FileInfo[] a list of files to compare.
.OUTPUTS
System.IO.FileInfo representing the newest of the files compared.
.FUNCTIONALITY
Files
.LINK
Test-NewerFile.ps1
.EXAMPLE
ls C:\java.exe -Recurse -ErrorAction Ignore |Find-NewestFile.ps1
Directory: C:\Program Files (x86)\Minecraft\runtime\jre-x64\1.8.0_25\bin
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2017-02-05 15:03 190888 java.exe
#>
#Requires -Version 3
[CmdletBinding()][OutputType([IO.FileInfo])] Param(
# The list of files to search.
[Parameter(ValueFromPipeline=$true,ValueFromRemainingArguments=$true)]
[IO.FileInfo[]] $Files
)
Begin { $NewestFile = $null }
Process { $Files |ForEach-Object {if(Test-NewerFile.ps1 $NewestFile $_){$NewestFile=$_}} }
End { $NewestFile }