# SS64 Forum

You are not logged in.

## #1 09 Feb 2020 12:43

Rekrul
Member
Registered: 17 Apr 2016
Posts: 69

### Backslash in drive path optional unless you're in a dir on that drive?

This isn't really a problem, I'm just curious if there's some reason for this behavior.

Let's say that you're in the root of external drive G:, and there's a directory called "Temp". If you type;

``IF EXIST "G:Temp" ECHO Exists!``

It prints Exists! because it finds it, despite the missing backslash after "G:".

However if you type;

``````CD Temp\
IF EXIST "G:Temp" ECHO Exists!``````

Nothing prints because it can't find that directory without the backslash. In fact it fails if you're in any directory on that drive. However it works fine from within directories on other drives.

Is there some reason for this, or is it just a weird quirk?

Offline

## #2 09 Feb 2020 13:43

Simon Sheppard
Registered: 27 Aug 2005
Posts: 1,055
Website

### Re: Backslash in drive path optional unless you're in a dir on that drive?

If you dont specify a parent folder, either \ or any other folder, then IF EXIST will look for the item in the current directory, which could be g:\temp or g:\documents\temp or whatever folder you are in.

The Windows CMD shell holds a current directory for each drive and for each session.

So you can have a current drive of C: and change the directory on g: with
C:> cd g:\documents
C:>
C:> g:
G:\documents>
https://ss64.com/nt/cd.html

Offline

## #3 10 Feb 2020 05:13

Rekrul
Member
Registered: 17 Apr 2016
Posts: 69

### Re: Backslash in drive path optional unless you're in a dir on that drive?

Simon Sheppard wrote:

If you dont specify a parent folder, either \ or any other folder, then IF EXIST will look for the item in the current directory, which could be g:\temp or g:\documents\temp or whatever folder you are in.

The Windows CMD shell holds a current directory for each drive and for each session.

So you can have a current drive of C: and change the directory on g: with
C:> cd g:\documents
C:>
C:> g:
G:\documents>