Testing If a Directory Exists from a Batch File

Going old school here. . .

To check for the presence of a directory (or folder) you can use the IF EXIST statement. For example, to test for C:TEMP and then change to C:TEMP if it exists, else create the directory and change to it, use the following batch file:

C:
IF NOT EXIST C:TEMP GOTO MAKEDIR
CD TEMP
EXIT

:MAKEDIR
MD C:TEMP
CD TEMP
EXIT

One thought on “Testing If a Directory Exists from a Batch File”

Leave a Reply

Your email address will not be published. Required fields are marked *