Why Does “dir C:” Return Such Different Results From “dir C:\”?




As you learn about using the command line and what the various commands can do, you may wonder why you get such different results for what appears to be nearly identical commands. With that in mind, today’s SuperUser Q&A post helps a confused reader understand the differences.

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 Nuno Peralta wants to know why he gets such different results from nearly identical commands:

I have accidentally discovered that if I use:
dir C:\

I get a list of files that are direct children of the C: drive (in the root). However, if I use:
dir C:

I get a huge list of files (dll, exe, cpl, etc.) whose location I am not even sure of.

Do you know why this happens and where this list comes from? 
Why does he get such different results from nearly identical commands?

The Answer

SuperUser contributor TOOGAM has the answer for us:

Specifying DIR location will show you the contents of the location. Specifying C: on many commands, including the DIR command, refers to the C Drive, and refers to the current directory. To see your current directory, type this:
c:
cd 
The cd command is typically used to change which directory is considered the current one. However, in MS-DOS (and similar operating systems, including modern Microsoft Windows, but not including Unix), running cd by itself will show you the current directory.
In all probability, if you have not been using the cd command, then your current directory is probably the directory that your operating system was installed to (at least that is a common behavior for Microsoft Windows systems). You can do this: 
cd “C:\Program Files”
cd
dir c: 
That will show you the contents of C:\Program Files. Similarly, you can do something like copy C:*.* and all contents from the current directory will be copied.

When you specify C:\, then the backslash indicates the “root” directory, also known as the “top level” directory. That might, or might not be the same thing as your current directory. 
If you just specify DIR \, then the current drive will be assumed to be the one you want. You can type something like C: or D: as an entire command on a line by itself to change which drive is considered the current one. If you just specify DIR, then the current drive and the current directory will be assumed to be the one you wanted.

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.
Previous Post Next Post