Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Created December 27, 2018 15:17
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 gitfvb/b1872cc407b2f1bda44c0c5cbcf08fc0 to your computer and use it in GitHub Desktop.
Save gitfvb/b1872cc407b2f1bda44c0c5cbcf08fc0 to your computer and use it in GitHub Desktop.
List all folders with full path that are older than the start of this week - the folders are named with the dateformat "yyyyMMddHHmmss"
################################################
#
# PREPARATION / ASSEMBLIES
#
################################################
# Load scriptpath
if ($MyInvocation.MyCommand.CommandType -eq "ExternalScript") {
$scriptPath = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
} else {
$scriptPath = Split-Path -Parent -Path ([Environment]::GetCommandLineArgs()[0])
}
cd $scriptPath
################################################
#
# CLEAN FOLDERS
#
################################################
$diffToStartOfWeek = ( [datetime]::Now.DayOfWeek.value__ - 1 ) * -1
$startOfWeek = [datetime]::Now.AddDays($diffToStartOfWeek)
cd "C:\xyz"
Get-ChildItem -Path ".\" -Directory | ForEach {
$folderTimestamp = [datetime]::ParseExact($_.BaseName, "yyyyMMddHHmmss", $null)
$timespan = New-TimeSpan -Start $startOfWeek -end $folderTimestamp
if ( $timespan.Days -lt 0 ) {
$_.FullName
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment