Created
December 27, 2018 15:17
-
-
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################ | |
# | |
# 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