Title: Select-String's wildcard matching for -Path should exclude directories · Issue #4820 · PowerShell/PowerShell · GitHub
Open Graph Title: Select-String's wildcard matching for -Path should exclude directories · Issue #4820 · PowerShell/PowerShell
X Title: Select-String's wildcard matching for -Path should exclude directories · Issue #4820 · PowerShell/PowerShell
Description: Select-String only supports file paths passed to -LiteralPath and (in resolved form) -Path. As an aside: Even though the error message when you pass a directory path is technically correct, it could be more helpful: Select-String: The fi...
Open Graph Description: Select-String only supports file paths passed to -LiteralPath and (in resolved form) -Path. As an aside: Even though the error message when you pass a directory path is technically correct, it coul...
X Description: Select-String only supports file paths passed to -LiteralPath and (in resolved form) -Path. As an aside: Even though the error message when you pass a directory path is technically correct, it coul...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/4820
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Select-String's wildcard matching for -Path should exclude directories","articleBody":"`Select-String` only supports _file_ paths passed to `-LiteralPath` and (in resolved form) `-Path`.\r\n\r\nAs an aside: Even though the error message when you pass a _directory_ path is technically correct, it could be more helpful:\r\n\r\n\u003e Select-String: The file /path/to/dir cannot be read: Access to the path '/path/to/dir' is denied.\r\n\r\nIt would be convenient to automatically exclude _directory_ matches from what a wildcard expression passed to `-Path` resolves to, given that they won't be processed anyway.\r\n\r\nThis would allow searching all files in a directory, whatever extension they have or whether they have one at all, with `Select-String -Path * findme`\r\n\r\nOn a side note: `-Path`'s wildcard matching currently _invariably_ excludes _hidden_ files, so the only way to include hidden files in the search is to pipe from `Get-Item` / `Get-ChildItem` with `-Force`.\r\n\r\nCurrent behavior\r\n------------------\r\n\r\nSetup: Create a directory that contains a subdirectory and a text file:\r\n\r\n```powershell\r\nPush-Location (New-Item -Type Directory -Force (Join-Path ([io.path]::GetTempPath()) $PID))\r\n$null = New-Item -Type Directory subd\r\n'hi' \u003e t.txt\r\n```\r\n\r\nUsing wildcard expression `*` reports an error, because `*` also matches the _directory_, `subd`:\r\n\r\n```powershell\r\n\u003e Select-String -Path * hi\r\nSelect-String : The file .../subd cannot be read: Access to the path '.../subd' is denied.\r\n...\r\n\r\nt.txt:1:hi\r\n\r\n```\r\n\r\nDesired behavior\r\n-----------------\r\n\r\nThe directory wildcard match should be ignored.\r\n\r\n```powershell\r\n\u003e Select-String -Path * hi\r\n\r\nt.txt:1:hi\r\n\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\nPowerShell Core v6.0.0-beta.6 on macOS 10.12.6\r\nPowerShell Core v6.0.0-beta.6 on Ubuntu 16.04.3 LTS\r\nPowerShell Core v6.0.0-beta.6 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\nWindows PowerShell v5.1.15063.502 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-09-12T20:12:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/4820/PowerShell/issues/4820"}
| 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:e8f81373-773e-5857-c50c-dbcc11fc6765 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B048:3E6E7A:EFD45D:15A0529:6A579D84 |
| html-safe-nonce | c9eb9258dd5768546f973cb7ea0ddda58660414d0dc912ce84c0c731fbda8a06 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDQ4OjNFNkU3QTpFRkQ0NUQ6MTVBMDUyOTo2QTU3OUQ4NCIsInZpc2l0b3JfaWQiOiI5MjYzNjg2NDMwMjEyNDk5MjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d72833a4aa35efa6078cf62cb10fabf792f6e10eadfd84488e7264e49738c243 |
| hovercard-subject-tag | issue:257166401 |
| 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/4820/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aace7f28d0ac6b48d0d014f439857f30c72e1244b08f4987d38f15706b0be6b8/PowerShell/PowerShell/issues/4820 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aace7f28d0ac6b48d0d014f439857f30c72e1244b08f4987d38f15706b0be6b8/PowerShell/PowerShell/issues/4820 |
| og:image:alt | Select-String only supports file paths passed to -LiteralPath and (in resolved form) -Path. As an aside: Even though the error message when you pass a directory path is technically correct, it coul... |
| 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 | 017a07c29bdd8a37b5907fc9a689338deb7103b5af7f56714193b2700229b3df |
| 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 | 0dd6847d644323df8f8c1368c065f9f630095e3b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width