Quick Links

Sometimes you may end up with unexpected results when running commands, so learning the "why" behind the results can be very interesting. With that in mind, today's SuperUser Q&A post has the answer to a curious reader's question.

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

The Question

SuperUser reader Luu Vinh Phuc wants to know why dir *.* lists all files and folders:

When I run the dir *.* command, it produces unexpected results. Even files and folders without any dot in the name are listed. For example:

Why is that? Is there any way to only list files with a dot?

Why does dir *.* list all files and folders?

The Answer

SuperUser contributor Fleet Command has the answer for us:

The DIR command comes from a time when:

  • A period (.) was not allowed as a character in file or folder names
  • File and folder names were restricted to 8 characters for names and 3 characters for extensions

Therefore, by that standard, *.* meant whatever the name and whatever the extension. It did not mean a string containing a ".", which may or may not have characters before or after the ".".

Microsoft's policy is preserving backward compatibility, so that interpretation of *.* is retained. But in Windows PowerShell, *.* means a string containing a ".", which may or may not have characters before or after the ".".


Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.