Remove all Cached folders from imagegen with powershell

by Damiaan Peeters 3. June 2015 22:08

UDPATE: read the comments for simple oneliners!

Sometimes you need to say goodbye to a good friend.  ImageGen served us very well.  But we made the switch to ImageProcessor some time ago.

The only thing, if you start to clean the media folder, are all the "Cached" folders.  To remove them we wrote a little powershell script to help us out.


$path = "C:\Projects\parentfoldertoclean"
cd $path

# delete Cached folders
get-childitem -Include Cached -Recurse -force | Remove-Item -Force –Recurse

# Delete any empty directories left behind after deleting the old files.
Get-ChildItem -Recurse -Force | Where-Object { $_.PSIsContainer -and (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }) -eq $null } | Remove-Item -Force -Recurse

Who.I.am

Certified Umbraco Master, Part of Umbraco Certified partner comm-it, .Net and Azure developer, seo lover. Magician in my spare time.

Month List