C:\Temp\ifc has about 297 folders inside it with roughly 4.1 million files spread amongst them.
Using a script I found elsewhere on this site, I wrote the following to delete all 'files' which are older than 1 hour.
$TargetFolder = “C:\Temp\ifc”
$NumberRange = "-1"
Get-ChildItem $TargetFolder -Recurse | Where {$_.lastwritetime -lt (Get-Date).AddHours($NumberRange)} | Remove-Item
The problem I am having is that it is deleting the sub-folders as well (if these folders end up with no files in them).
What can I add to this so that it leaves the folder structure in place?
Many Thanks.