question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dir *. has no output

See original GitHub issue

dir *.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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
vexx32commented, Mar 20, 2021

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

1reaction
mklement0commented, Mar 21, 2021

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):

gci -Filter *.  # by contrast `dir *.` is the same as  `gci -Path *.` and therefore `Get-ChildItem -Path *.`

(I’ve used alias gci for Get-ChildItem, because using the alias dir can cause confusion, notably the expectation that everything works as in cmd.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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found