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:
Why does dir . list all files and folders?
Why is that? Is there any way to only list files with a dot?
The Answer
SuperUser contributor Fleet Command has the answer for us:
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.
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 “.”.