Title: `Remove-Item`: adding `-Recurse` when `-Filter` is also used ignores the filter, targets *all* items. · Issue #20651 · PowerShell/PowerShell · GitHub
Open Graph Title: `Remove-Item`: adding `-Recurse` when `-Filter` is also used ignores the filter, targets *all* items. · Issue #20651 · PowerShell/PowerShell
X Title: `Remove-Item`: adding `-Recurse` when `-Filter` is also used ignores the filter, targets *all* items. · Issue #20651 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/20651
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`Remove-Item`: adding `-Recurse` when `-Filter` is also used ignores the filter, targets *all* items.","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\n### Steps to reproduce\r\n\r\nThis is a serious problem that can result in unwanted deletion of both files and subdirectories.\r\n\r\nRelated:\r\n* #16153\r\n* #20637\r\n\r\n```powershell\r\n# Create and switch to a temp. dir.\r\nPush-Location ($tmpDir = New-Item -Force -Type Directory (Join-Path temp: $PID))\r\n\r\n# Create two sample files and a sample subdir.\r\n'1.txt', '2.csv' | % { '' > $_ }\r\n$null = New-Item -Force -Type Directory subdir\r\n\r\n# Use -Filter *.txt alone \r\nRemove-Item * -Filter *.txt -WhatIf\r\n\r\n'---'\r\n\r\n# Use -Filter *.txt with -Recurse\r\nRemove-Item * -Filter *.txt -Recurse -WhatIf\r\n\r\n# Clean up\r\nPop-Location\r\n$tmpDir | Remove-Item -Recurse \r\n```\r\n\r\n### Expected behavior\r\n\r\n```console\r\nWhat if: Performing the operation \"Remove File\" on target \"/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/1.txt\".\r\n---\r\nWhat if: Performing the operation \"Remove File\" on target \"/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/1.txt\".\r\n```\r\n\r\n\r\n### Actual behavior\r\n\r\n```console\r\nWhat if: Performing the operation \"Remove File\" on target \"/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/1.txt\".\r\n---\r\nWhat if: Performing the operation \"Remove Directory\" on target \"/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/subdir\".\r\nWhat if: Performing the operation \"Remove File\" on target \"/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/1.txt\".\r\nWhat if: Performing the operation \"Remove File\" on target \"/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/2.csv\".\r\n```\r\n\r\nThat is, *all items* were targeted when -Recurse was added\r\n\r\n### Error details\r\n\r\n_No response_\r\n\r\n### Environment data\r\n\r\n```powershell\r\nPowerShell 7.4.0-rc.1\r\n```\r\n\r\n\r\n### Visuals\r\n\r\n_No response_","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2023-11-07T14:24:29Z","url":"https://github.com/PowerShell/PowerShell/issues/20651"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7d86a267-71d0-03b2-53d5-1d3edc0b2294 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E760:5C8B1:663162:943123:6AFD8F0C |
| html-safe-nonce | 7d761f7a2a04245da2f30eb39e0ab7f9f60d24a727b84ca967ac687316e3598f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzYwOjVDOEIxOjY2MzE2Mjo5NDMxMjM6NkFGRDhGMEMiLCJ2aXNpdG9yX2lkIjoiNTE2Mjk4NDYwMzU0Mjk4MjQxMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f43b053b8bd0fcbaeb4b539f11b00b7826ab1a0b542bdd0c4ec0cb235a6ed19f |
| hovercard-subject-tag | issue:1981488169 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/20651/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9bbc04d50c3c5794e4e767cc803123dc16c1435315ccc8d8e54084320ee2318b/PowerShell/PowerShell/issues/20651 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9bbc04d50c3c5794e4e767cc803123dc16c1435315ccc8d8e54084320ee2318b/PowerShell/PowerShell/issues/20651 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 927a6c5ab1c32b38830f1b9d3050c0b9e9aa92e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width