dir *. has no output
See original GitHub issuedir *.exe
or dir *.*
works as intended. However, the expected output of dir *.
(displaying all folders in the current working directory) is not functioning. Instead, a workaround is to type cmd /c "dir *."
Steps to reproduce
In pwsh, go to a folder with subfolders.
enter command dir *.
Expected behavior
displays all subfolders in cwd (and no other file types)
Actual behavior
No output, no errors
Environment data
PSVersion = 7.1.3 PSEdition = Core GitCommitId = 7.1.3 OS = Microsoft Windows 10.0.19042 Platform = Win32NT PSCompatibleVersions = {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion = 2.3 SerializationVersion = 1.1.0.1 WSManStackVersion = 3.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
sql server - SQLCMD :!! Dir producing no output
Watching it with process explorer shows that when attempting to run a command it creates an invalid path to cmd.exe by appending "C:\WINDOWS\ ......
Read more >Dir
Displays a bare list of directories and files, with no additional information. The /b parameter overrides /w. /l, Displays unsorted directory ...
Read more >No output when run doxygen in high level directory #9500
I run "doxygen Doxyfile" in the code path, command successfully, and output directory is created with content(index.html, etc). No ...
Read more >permissions - No output from locate command
When I authenticate using my Active Directory credentials, domain users is the primary group allocated to me by Winbind. A while ago I...
Read more >Failure to read output files - no output files in directory
I'm using Linux console version (Debian) and never got any problems with STRUCTURE. So i guess the computational part of STRUCTURE is very...
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 FreeTop 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
Top GitHub Comments
I can see the logic here, but I think the
dir *.
behaviour in cmd.exe is more of a workaround for not having an explicit directory filter than anything else.For the same in PowerShell, use the -Directory flag;
Get-ChildItem -Directory
/dir -d
Good point, @vexx32, but note that alias
-d
for-Directory
doesn’t actually work and will be removed - see #14700; prefix matching with-di
works, however.@UnkleUnkle, for listing directories, @vexx32’s solution is the best approach (your command would also include files that happen to have no filename extension), but just to explain your symptom:
The fundamental problem is that in
cmd.exe
and in the WinAPI file-enumeration APIs wildcard expressions have special behavior built in that PowerShell’s wildcard expressions do not.If you want to get the same behavior as in
cmd.exe
, use the-Filter
parameter rather than the (positionally implied)-Path
parameter (the latter uses only PowerShell’s wildcards):(I’ve used alias
gci
forGet-ChildItem
, because using the aliasdir
can cause confusion, notably the expectation that everything works as incmd.exe
You can shorten-Filter
to-fi
, which is the shortest prefix that unambiguously identifies the-Filter
parameter; generally, aliases and parameter-name prefixes should only be used interactively, not in scripts).As for why PowerShell’s wildcard expressions behave differently: they are not specific to matching file names, but are used pervasively throughout PowerShell and therefore match any input string as-is, without making assumptions about a
.
being special, for instance.Therefore, wildcard
*.
matches any string that ends in a verbatim.
, which file names generally don’t do. E.g.,'foo' -like '*.'
is$false
, whereas'foo.' -like '*.'
and'.' -like '*.'
are$true
.