13

What is the difference between "C:FILE.TXT" and "C:\FILE.TXT"?

Are they the same?

1 Answer 1

26

C:FILE.TXT refers to FILE.TXT in the current directory of drive C:

C:\FILE.TXT refers to FILE.TXT in the root directory of drive C: (C:\)

They are not the same.

Edit: Command Prompt Example:

Windows remembers a current working directory for each drive. Say you are working in directory C:\UTILS and then you change to drive F: and then to directory BIN on F::

C:\UTILS> F:
F:\> CD BIN
F:\BIN>

At this point the current working directory for C: is still C:\UTILS and the current working directory for F: is F:\BIN

You can verifiy this with the CD command:

F:\BIN> CD C:
C:\UTILS

F:\BIN>

Note that you did not change the working drive back to C: by using this command.

As you will see from the following command examples, the use of a backslash (\) immediately after a drive name (X:) makes the file location absolute. Ommiting the backslash automatically involves the current working directory for the drive.

F:\BIN> COPY F:PROGRAM.EXE C:    Copies* F:\BIN\PROGRAM.EXE to C:\UTILS\PROGRAM.EXE
F:\BIN> COPY F:PROGRAM.EXE C:\   Copies* F:\BIN\PROGRAM.EXE to C:\PROGRAM.EXE
F:\BIN> COPY F:\PROGRAM.EXE C:   Copies* F:\PROGRAM.EXE to C:\UTILS\PROGRAM.EXE

F:\BIN> COPY F:PROGRAM.EXE C:NEW\NEW_PROG.EXE   Copies* and renames
                                                F:\BIN\PROGRAM.EXE
                                                to C:\BIN\NEW\NEW_PROG.EXE
 

* 'Copies' means 'attempts to copy'. These commands will fail if the assumed directory structures and current working directories don't exist or are changed by another process.

In the case where the working directory is the root directory (eg. C:\) then C:PROGRAM.EXE and C:\PROGRAM.EXE point to the same location, but they have been arrived at by different methods.

13
  • 2
    Actually they can be the same if C:’s current directory is the root.
    – Synetech
    Jul 25, 2011 at 7:30
  • 3
    @Synetech; Just because they can refer to the same place doesn't mean they're the same thing
    – Phoshi
    Jul 25, 2011 at 7:48
  • Note that Windows NT doesn't track per-drive "current directories" anymore; this syntax is now only useful in the cmd.exe shell. In other programs, if a different drive than current is given, such path specifications will be always relative to that drive's root. Jul 25, 2011 at 8:19
  • @Phoshi, yes, they are the same in certain contexts. It’s like saying that int x is the same as int y; they are not ===, but they can be == if both have the same value. @grawity, of course windows apps (Win32, not just NT) have no per-drive cwd since it would mean nothing in that context. Regardless, it’s not just cmd; all console apps have it.
    – Synetech
    Jul 26, 2011 at 0:55
  • @Mike actually after reading through the answer i still can't tell the difference. could you elaborate it for a dumb user?
    – Pacerier
    Jul 29, 2011 at 17:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .