New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Could you please add a option to exclude a folder and also exclude its subfolders? #15159
Comments
That would indeed be useful. There is a related idea in #4126 - though that isn't obvious from the wording, and the idea isn't fully fleshed out - which has been green-lit, but not implemented: That is, the syntax would be something like: Get-ChildItem -Recurse -Exclude ExcludeFolder/* However, that would only include To support something open-ended, we'd need something like So perhaps the two ideas can be combined:
|
In my opinion, this is unnecessary. This will complicate the cmdlet. This functionality is very easy to replace with
But I am not against the idea itself, but for wider functionality of |
|
Personally I agree with @237dmitry where this cmdlet is already complex enough and adding even more parameters is just going to make things worse. I don't see how having an |
@jborean93, I definitely agree that a
What this doesn't give you is a simple way to say "exclude all
|
Your understanding is absolutely what I want, Thank you. |
Suppose you are in a folder "PowerShell\blah\blah", your code will output nothing. |
Suppose that you will create a specific regular expression for a specific case. |
Create it, please. |
What subfolder have to be excluded? <#
Path\To\Powershell\2
Path\To\Powershell\blah
Path\To\Powershell\2\test
Path\To\Powershell\blah\blah
Path\To\Powershell\blah\blah\powershell
Path\To\Powershell\blah\blah\powershell\test
#>
((Get-Childitem PowerShell -Recurse) -notmatch '.+\\powershell.+powershell\\?').FullName
<#
Path\To\Powershell\2
Path\To\Powershell\blah
Path\To\Powershell\2\test
Path\To\Powershell\blah\blah
#> |
Thank you. You are right. It's possible to implement it in your way. |
We could add a recurse predicate. De-facto we have it internally (for depth control) but we could have it as public parameter - a scriptblock. |
To make the regex for the given example fully robust and cross-platform, it would have to be something like: -notmatch '(^|[\\/])powershell[\\/](.+[\\/])?powershell([\\/]|$)' That said, that example would not - and, to me, need not - be addressed by To emulate what
but that:
As an aside: the difference in behavior between |
And if the subfolder(s) to exclude in the example is at a known level of the hierarchy, in combination with #4126, the solution would be |
I suggest more generic way: Get-ChildItem -RecurseCondition <ScriptBlock gets DirectoryInfo in $Item> -RecurseFilter <ScriptBlock gets FileInfo in $Item> This is greatly flexible. |
I think in this case @jborean93's concern about trying to pack too much functionality into a single cmdlet applies (I also don't understand how that would address the exclude-subtree use case - perhaps you can elaborate). What I - and @ssfjhh, I presume - had in mind was a simple extension of existing functionality that is based on the simplicity of name literals and wildcards (and potentially paths). I see the following as the primary use cases of
Get-ChildItem -Recurse -Include *.json
Get-ChildItem -Recurse -Directory -Include node_modules Note: Using
Note: Perhaps For instance, the following would then allow you to list all Get-ChildItem -Recurse -Include *.js, *.ts -ExcludeRecursive obj, bin, node_modules |
The Engine Working Group discussed this issue today. We believe this is a reasonable ask -- it would be nice to make it easier to exclude/include a folder completely with
|
From my experience with #12834:
|
IMO, @daxian-dbw's suggestion is the golden functionality for
There is no need for new parameter names here. The existing parameters should be able to infer the user's intended functionality based on the specified parameter set and the glob pattern they gave in the param. Moreover, the current |
This is probably an old argument, but to me if a folder is excluded, a user wouldn't expect it to be recursed into. How often has this question been asked on stackoverflow and reddit?
|
Summary of the new feature/enhancement
As a user I want PowerShell can exclude a folder and also exclude its subfolders and subfiles.
Proposed technical implementation details (optional)
For instance:
Then, the folder "ExcludeFolder" and all its subfolders and all files in it and its subfolders will be excluded.
"ExcludeFolderAndItsSubFolders " is only an example, it's a little long. Of course, you can choose any other better option name.
The text was updated successfully, but these errors were encountered: