dir C: vs dir C:\

TL;DR - dir C: will list the current directory on C: whatever that happens to be, as opposed to dir C:\ which will always list the \ root of C:.

Long story... At the command line prompt, cmd remembers the current directory for each drive it accessed during the session.

The current directory on a drive X: other than the current one can be set with cd X:\etc (without the /d switch which would also change the current drive to X:), and is returned by cd X: (without a \) - both noted in the cd /? help:

Type CD drive: to display the current directory in the specified drive.

Use the /D switch to change current drive in addition to changing current directory for a drive.

See Why does each drive have its own current directory? for background, including this quote.

Remembering the current directory for each drive has been preserved ever since [n.b. DOS], at least for batch files, although there isn’t actually such a concept as a per-drive current directory in Win32. In Win32, all you have is a current directory. The appearance that each drive has its own current directory is a fake-out by cmd.exe, which uses strange environment variables to create the illusion to batch files that each drive has its own current directory.

The strange environment variables referred to in the linked post What are these strange =C: environment variables? can be seen with set "" at the cmd prompt, for example:

C:\temp>cd X:\etc

C:\temp>cd C:
C:\temp

C:\temp>cd X:
X:\etc

C:\temp>set ""
=C:=C:\temp
=X:=X:\etc
ALLUSERSPROFILE=C:\ProgramData
[...]

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 current. 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 haven't been using the cd command, then your current directory is probably the directory that your operating system was installed to. (At least, that's 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. (You can type something like C: or D:, as an entire command (on a line by itself), to change which drive is considered to be the "current drive".) If you just specify DIR, then the current drive and the current directory will be assumed.


The reason you are getting two different directories is simple. The \ is the difference.

dir C:\ is asking for the directory listing of the C drive at its \. \ is the root folder.

dir C: is asking for the directory listing of where you are (or was last, if you changed drives)

If you're on the C drive and just type dir and hit enter, you will get the same contents of dir C:. If you're on a different drive, and type C: to change back to the C drive, then you'll end up in the directory that you saw when you typed dir C:.