You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remove-Item -Recurse with an -Include or -Filter argument mistakenly tries to remove the directory itself #16153
The problem affects -Exclude too, but use of -Exclude with file filters is treacherous and not meaningfully supported.
When you combine Remove-Item -Recurse with either -Include or -Filter, only those items inside the target directory subtree that match the pattern(s) are removed, as intended.
However, if you invoke such a command with . as the input path, i.e. from inside the target directory, the command fails, as an attempt is seemingly made to delete the directory itself:
237dmitry, I don't know whether things changed, but as of v7.3.10 / v7.4.0-rc.1, the workaround with * (or .\*) not only doesn't work, but blindly removes all items, i.e. ignores the filter - see:
Activity
237dmitry commentedon Sep 24, 2021
Success for both commands. Try input path
.\*7.1.4
mklement0 commentedon Sep 24, 2021
237dmitry, yes, that is a viable workaround (
*will do) - but it shouldn't be necessary, and that's what this issue is about.mklement0 commentedon Nov 7, 2023
237dmitry, I don't know whether things changed, but as of v7.3.10 / v7.4.0-rc.1, the workaround with
*(or.\*) not only doesn't work, but blindly removes all items, i.e. ignores the filter - see:Remove-Item: adding-Recursewhen-Filteris also used ignores the filter, targets *all* items. #20651