The solution when the resource is a file it is pretty straight-forward as indicated by others:
C:\> IF EXIST C:\CONFIG.SYS ECHO C:\CONFIG.SYS exists.
Unfortunately, the above does not work for directories. The EXIST function returns the same result for both missing and present folders. Fortunately, there is an obscure workaround:
C:\> IF NOT EXIST C:\FOLDER\NUL ECHO C:\FOLDER missing.
C:\> MD C:\FOLDER
C:\> IF EXIST C:\FOLDER\NUL ECHO C:\FOLDER exists.
It turns out that to support constructs like appending
>NUL on command statements, there is a sort of virtual file named "NUL" in every directory. Checking for its existence is equivalent to a check for the directory's existence.
This behavior is documented in a Microsoft knowledge base article ( https://support.microsoft.com/en-us/kb/65994 ) and I have confirmed its behavior on FreeDOS 1.1 and in a Windows 7 command shell.
EXTRA: The KB article indicates this technique can also be used to see if a drive is present. In the case of checking for drive existence, however, caveats exist:
Abort, Retry, Fail? error occurs if the drive is not formatted.
Using this technique to check for drive existence depends on device driver implementation and may not always work.