powershell - Remove folders recursively older than X days -


i have directory 12k folders multiple subfolders inside.

i'm trying remove empty folders older defined days, thing not remove folder (which last write time matches limit), has "younger" subfolder inside.

using 1 of (many found), examples (which modified bit), got close, unfortunately got rid of prepared folder (i created file in test folder check if deleted).

it appears doesn't go through sub folders.

here code:

$limit = (get-date).adddays(-180) $path = "path"  get-childitem -path $path -recurse -force | where-object {   ($_.psiscontainer -and $_.lastwritetime -lt $limit) -and   (get-childitem -path $_.fullname -recurse -force | where-object {     !$_.psiscontainer   }) -eq $null } | remove-item -force -recurse 

any ideas doing wrong it?


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -