A 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).
Get-ChildItem -File -Directory
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.
The combination of these switches is allowed, and nothing is output.
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)
I can work on this one.
@DdWr consider it yours! I'm only able to assign to collaborators, so don't worry about that, but I'll remove the Up-for-Grabs label. Thanks!
@mklement0 should -File -Directory in conjunction actually return everything and not be exclusive? Should it be an or and not an and.
@thezim:
It's debatable; here are the reasons I went with the AND interpretation, which led me to request that the switches be _mutually exclusive_:
Specifying _neither_ switch gives you _both_ files and directories _by default_; i.e, the default is _everything_, and adding _either_ -File or -Directory _takes things away_, so that using both -File and -Directory would take _everything_ away, which is why I think it makes no sense.
Get-ChildItem's help currently states:
To get only directories, use the -Directory parameter and omit the -File parameter. To exclude directories, use the -File parameter and omit the -Directory parameter
A potential reason to go with OR logic is that it would enable adding additional switches that go beyond the basic file/directory dichotomy, though arguably that is covered by the existing -Attributes parameter.
@SteveL-MSFT, any thoughts?
hmmm. and/or logic would be nice you are wrapping this and asking if files and folders should be included. being able to pass the bools directly to it like so -Directory:$IncludeDirectories -File:$IncludeFiles. With xor logic you would have to do something like if($IncludeDirectories){$params.add('Directory', $true)}.
Also, while I haven't looked at the cmdlet or provider, implementing exclusive parameters can become tricky if there are parameter sets already in use.
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.
You claims don't seem quite right:
Get-ChildItem's -File and -Directory switches limit the output to files only / directories only, respectively.
This outputs a FileInfo object, so the -Directory switch is not limiting the output to only directories:
Get-ChildItem -Directory D:\Testfolder\testfile.txt
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).
This outputs a FileInfo object, so the output when specifying both switches is not always nothing:
Get-ChildItem -File -Directory D:\Testfolder\testfile.txt
@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.
Most helpful comment
@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-Directoryor-Filewas provided.