Skip to content

Instantly share code, notes, and snippets.

@mshock
Created March 27, 2014 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshock/9809113 to your computer and use it in GitHub Desktop.
Save mshock/9809113 to your computer and use it in GitHub Desktop.
recursively retrieve file list and delete files older than 60 days (TODO: add CLI args for age and dirs)
function cleandir($dir) {
$a = Get-ChildItem $dir -filter *.* -recurs
foreach($x in $a)
{
$y = ((Get-Date) - $x.CreationTime).Days
if ($y -gt 60 -and $x.PsISContainer -ne $True)
{$x.Delete()}
}
}
cleandir('C:\dir');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment