I have a list of filenames in a text file like this:
f1.txt
f2
f3.jpg
How do I delete everything else from a folder except these files in P
actually this only seems to work for the first directory rather than recursing - my altered script recurses properly.
$exclusions = Get-Content .\exclusions.txt
dir -rec | where-object {-not($exclusions -contains [io.path]::GetFileName($_))} | `
where-object {-not($_ -is [system.IO.directoryInfo])} | remove-item -whatif