Title: Inconsistencies between Get-ChildItem and Remove-Item with respect to -Recurse and -Include · Issue #3727 · PowerShell/PowerShell · GitHub
Open Graph Title: Inconsistencies between Get-ChildItem and Remove-Item with respect to -Recurse and -Include · Issue #3727 · PowerShell/PowerShell
X Title: Inconsistencies between Get-ChildItem and Remove-Item with respect to -Recurse and -Include · Issue #3727 · PowerShell/PowerShell
Description: Update: Based on Andrew Stanton (@StingyJack)'s feedback, part of this issue may be related to a longstanding known Remove-Item problem currently documented as: When it is used with the Include parameter, the Recurse parameter might not ...
Open Graph Description: Update: Based on Andrew Stanton (@StingyJack)'s feedback, part of this issue may be related to a longstanding known Remove-Item problem currently documented as: When it is used with the Include par...
X Description: Update: Based on Andrew Stanton (@StingyJack)'s feedback, part of this issue may be related to a longstanding known Remove-Item problem currently documented as: When it is used with the Include...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/3727
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistencies between Get-ChildItem and Remove-Item with respect to -Recurse and -Include","articleBody":"_Update_: Based on @StingyJack's feedback, part of this issue may be related to a longstanding _known `Remove-Item` problem_ [currently documented as](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-item?view=powershell-6):\r\n\r\n> When it is used with the `Include` parameter, the `Recurse` parameter might not delete all subfolders or all child items. This is a known issue. \r\n\r\n---\r\n\r\n`Get-ChildItem` allows the following idioms to look for matching files on _all_ levels of the target directory's hierarchy:\r\n\r\n```powershell\r\nGet-ChildItem *.txt -Recurse\r\nGet-ChildItem . -Recurse -Include *.txt\r\n```\r\n\r\nBy contrast, these idioms currently do _not_ work with `Remove-Item`:\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\nSet-Location ~\r\n\r\nGet-ChildItem *.txt -Recurse\r\nGet-ChildItem . -Recurse -Include *.txt\r\n\r\nRemove-Item *.txt -Recurse -WhatIf\r\nRemove-Item . -Recurse -Include *.txt -WhatIf\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\nAll 4 commands should output / target the same set of files, across the directory hierarchy.\r\n\r\nActual behavior\r\n---------------\r\n\r\nThe `Get-ChildItem` commands behave as expected.\r\n\r\nThe `Remove-Item` commands do not:\r\n\r\n* `Remove-Item *.txt -Recurse -WhatIf` only targets items _directly_ in the target directory (does not recurse) \r\n * This behavior is sensible, but it deviates from `Get-ChildItem`'s behavior - see #5699\r\n\r\n* `Remove-Item . -Recurse -Include *.txt -WhatIf` fails. \r\nE.g., on macOS: `Remove-Item : Cannot remove the item at '/Users/jdoe' because it is in use.`; i.e., an attempt is made to blindly remove `.`, without considering the `-Include` wildcard pattern.\r\n\r\n * Note that the problem does _not_ occur if you target a directory by _name or path_, from a _different_ directory (rather than with `.` from _inside_ it).\r\n\r\nEnvironment data\r\n----------------\r\n\r\n\r\n```powershell\r\nPowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on macOS 10.12.4\r\nPowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Microsoft Windows 10 Pro (64-bit; v10.0.14393)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-05-07T21:16:48Z","url":"https://github.com/PowerShell/PowerShell/issues/3727"}
| 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:ad3862a2-6d99-6966-7ec4-1e6d40f2b611 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E876:25FFAF:B23B42:FE4FDD:6AFDA632 |
| html-safe-nonce | a43a7c92812d2b59981fc95e09bf3a29cc0ac0cea1743c18d0422be884778ab0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODc2OjI1RkZBRjpCMjNCNDI6RkU0RkREOjZBRkRBNjMyIiwidmlzaXRvcl9pZCI6Ijg3OTkzODUxMDM1NTA0OTAxNjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 54e5f11c3c47d2bb23abf76b848dd89d2ea471e818b18da0d14e41bcea1b1192 |
| hovercard-subject-tag | issue:226895199 |
| 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/3727/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3a117c6088e924825acf334a5f67c519966891788825aa1dd1bde47d9a98da1b/PowerShell/PowerShell/issues/3727 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3a117c6088e924825acf334a5f67c519966891788825aa1dd1bde47d9a98da1b/PowerShell/PowerShell/issues/3727 |
| og:image:alt | Update: Based on Andrew Stanton (@StingyJack)'s feedback, part of this issue may be related to a longstanding known Remove-Item problem currently documented as: When it is used with the Include par... |
| 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 | 0ddf53eb35c87f1f8df13dbf75c3bdadbfc6e969 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width