Get-ChildItem -File and -Directory should be mutually exclusive
See original GitHub issueA minor problem, and perhaps rare in practice.
Get-ChildItem
’s -File
and -Directory
switches limit the output to files only / directories only, respectively.
Therefore, it is pointless to allow both of them to be specified, given that no filesystem item can be both a file and a directory, and the output will always be nothing (null collection).
Steps to reproduce
Get-ChildItem -File -Directory
Expected behavior
An error indicating that incompatible switches were used, which would currently come in the form of parameter set cannot be resolved using the specified named parameters.
Actual behavior
The combination of these switches is allowed, and nothing is output.
Environment data
PowerShell Core v6.0.0-beta.8 on macOS 10.13
PowerShell Core v6.0.0-beta.8 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.8 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Get-ChildItem - PowerShell
Locations are exposed to Get-ChildItem by PowerShell providers. A location can be a file system directory, registry hive, or a certificate store.
Read more >How to skip error of Get-ChildItem returning Access denied
I have a problem with my powershell script, i'm trying to find a file in a folder recursivly. The folder where i am...
Read more >Pruning File Trees and Extending Cmdlets - Simple Talk
Get -ChildItem provides options that let you clamber recursively through a directory tree, include or exclude system items, or filter your output ...
Read more >Get-ChildItem PowerShell Ultimate Guide
The PowerShell cmdlet Get-ChildItem obtains objects from one or more specified locations, such as a file system directory, registry hive or ...
Read more >Mutually exclusive files and folders
Manually finding out and deleting folders is gonna be a very time consuming process and I don't wanna go for it. So can...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@HumanEquivalentUnit I think you hit upon another edge case. Since you provided a file to
-Path
, it can’t find any directories. Perhaps technically, it should have returned an error that it can’t get child items of a file regardless if-Directory
or-File
was provided.Thinking about this, I can see how
-File
and-DIrectory
could be interpreted as OR or AND. I don’t have a strong opinion either way on this one. However, if we change it so that the flag means “Include” (aka OR) where we now return everything compared to now where we return nothing (aka AND), that could break someone who was constructing the args programmatically.Personally, I think this issue probably isn’t worth spending additional time on vs some other issues and would propose
Won't Fix
and leave it the way it is.