Skip to content

Instantly share code, notes, and snippets.

@ezeeetm
Last active December 19, 2017 19:01
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 ezeeetm/f220e1c91b57ceeac1aedce102e17206 to your computer and use it in GitHub Desktop.
Save ezeeetm/f220e1c91b57ceeac1aedce102e17206 to your computer and use it in GitHub Desktop.
for nate...
<#
.SYNOPSIS
deletes files on login by file age and a list of file name regular expressions
.DESCRIPTION
srsly man, that's all it does.
.EXAMPLE
.\dloadCleanup.ps1
#>
# change these values to suit your needs
$regexList = @("^imageLinkProcessor.*pdf$", "^message.*mp3$")
$ageInDays = 14
# /change values
# don't change these
$downloadsPath = "$env:USERPROFILE\Downloads"
$deleteBeforeDate = (Get-Date).AddDays(-$ageInDays)
foreach ($regex in $regexList)
{
$offendingFiles = Get-ChildItem $downloadsPath | Where-Object {$_.Name -match $regex -and $_.CreationTime -lt $deleteBeforeDate}
foreach ($offendingFile in $offendingFiles)
{
Remove-Item -Force $offendingFile.FullName
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment