Aug 222011
On UNIX, it’s simple to delete matching files in a directory, over a certain age (e.g., all .txt files over 2 days old):
find /some/directory -type f -ctime +2 -name \*.txt -exec rm -f '{}' \;
On Windows, it’s ridiculously complicated. Here’s a PowerShell script, modified from somewhere….:
$a = Get-ChildItem 'C:\Temp\subdir\*' -include *.txt if ($a.count -gt 1) { foreach($x in $a) { $y = ((Get-Date) - $x.CreationTime).Days if ($y -gt 7 -and $x.PsISContainer -ne $True) { #$x.Delete() #uncomment here to delete Write-Host $x } } }
Sorry, the comment form is closed at this time.