Reputation: 4939
I have a large number F of files to sort through (5M+) and want to delete everything older than N days.
Is there any way of starting to delete files before the whole set has been identified -- perhaps equivalent to
System.IO.DirectoryInfo($folder).EnumerateFiles( ... )
in C#?
Upvotes: 0
Views: 250
Reputation: 978
The Get-ChildItem already does this. Files are passed down the pipes as soon as they are processed. Try this;
$NDays = -5
dir *.* | where{$_.CreationTime -lt (Get-Date).AddDays($NDays)} | Remove-Item
Upvotes: 2