first from yesterday

This commit is contained in:
Thijs Stobbelaar 2023-11-06 16:25:31 +01:00
parent fe7e81c2fa
commit c9fa618831

View file

@ -46,7 +46,7 @@ function get-killstats {
}
}
# Get the latest file in the directory by last modification time
try {
$filesarray = @()
$files = Get-ChildItem -Path "$scriptroot/../data/archive/" -File -ErrorAction Stop
@ -56,17 +56,14 @@ try {
$culture = [Globalization.CultureInfo]::InvariantCulture
$dateTime = [datetime]::ParseExact($dateinfile, $format, $culture)
$filesarray += [PSCustomObject]@{name = $file.Name; date = $dateTime }
}
$latestFile = ($filesarray | where-object { ($_.date -gt (get-date).AddDays(-2)) -and ($_.date -lt (get-date).AddDays(-1))} | Sort-Object date)[-1]
$latestFile = ($filesarray | where-object { ($_.date -gt (get-date).AddDays(-2)) -and ($_.date -lt (get-date).AddDays(-1))} | Sort-Object date)[0]
$latestFile = Get-Item -Path "$scriptroot/../data/archive/$($latestFile.name)"
Write-Output "Found file $($latestFile.FullName)"
}
catch {
$latestFile = @()
}
# Display the result