powershell - Deleting all folders/files except for one folder and all root-files -


i've had months away powershell excuse me if obvious..

i have directory containing hundreds of filed , folders, , delete except files in root directory , 1 of subfolders.

i creating scheduled task once week.

this have far:

get-childitem -recurse | ?{ $_.psiscontainer } | remove-item 

but quite obvious deleting folders..

do want keep contents of 1 subfolder or subfolder itself? former this:

get-childitem "c:\foo" -exclude "subfoldername" | ? { $_.psiscontainer } |   remove-item -recurse -force 

for latter delete contents of subfolder in second step:

get-childitem "c:\foo" -exclude "subfoldername" | ? { $_.psiscontainer } |   remove-item -recurse -force get-childitem "c:\foo\subfoldername" | remove-item -recurse -force 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -