7zip compress same dated files into one

I suppose your log files all have the same date format? Also, why do you write AddDays(-2) if you want yesterday? I suppose you mean AddDays(-1)

A very simple approach to get only yesterday’s files would be a wildcard filter:

$filter = (Get-Date).AddDays(-1).ToString("MM_dd_yyyy")
$files = Get-ChildItem $path -Filter "*$filter.log"

Or, if you just want files older than 1 day you can do:

$today = (Get-Date).Date
Get-ChildItem $path | where {
   ($today - [DateTime]($_.Name -replace '.*(\d{2})_(\d{2})_(\d{4}).*', '$3-$1-$2')).TotalDays -ge 1

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top