Created
June 9, 2015 09:07
-
-
Save kfstorm/2081e45a60e9480a889c to your computer and use it in GitHub Desktop.
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
$rootPath = "D:\Advertiser" | |
$deleteFileBefore = New-Object -typename System.DateTime -argumentlist (2013,12,25,0,0,0) | |
$root = New-Object -typename System.IO.DirectoryInfo -argumentlist $rootPath | |
foreach ($file in $root.GetFiles(“*”, [System.IO.SearchOption]::AllDirectories)) | |
{ | |
if ($file.LastWriteTime -le $deleteFileBefore) | |
{ | |
echo ("Deleting", $file.FullName -join " "); | |
$file.Delete(); | |
} | |
} | |
foreach ($subDir in $root.GetDirectories(“*”, [System.IO.SearchOption]::AllDirectories)) | |
{ | |
$subDir.Refresh() | |
if ($subDir.Exists) | |
{ | |
$filesCount = $subDir.GetFiles(“*”, [System.IO.SearchOption]::AllDirectories).Length; | |
if ($filesCount -eq 0) | |
{ | |
echo ("Deleting", $subDir.FullName -join " "); | |
$subDir.Delete($True); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment