powershell - power shell remove-item recurse sub directory 3 level down -
i can't figure out way recursively remove folders except sub-sub directory in each folder called "broadcast"
dir ->subdir1 -->main -->broadcast ->subdir2 -->main -->broadcast ->test
i want keep subdir#\broadcast folders , test folder. problem code below removes subdir1 , subdir2 in few recursion below, removes sub-sub directory
get-childitem -path $copy_file -recurse | select -expandproperty fullname | {$_ -notlike '*broadcast\*' -and $_ -notlike '*testing*'} | sort length -descending | remove-item -force
i can't use -force /a because list when sort includes subdir1 , subdir2...
it prompt me "this item has children..." [y] yes [a] yes all... [l] no
i want automatically select l
any suggestions? thank in advance... did through couldn't find exact solution looking for.
this exclude 'broadcast' folder (you can replace your) , can pass object remove-item
get-childitem -path d:\ -recurse -exclude @('broadcast') -directory | foreach- object($_){ write-host $_.fullname }
Comments
Post a Comment