Loading

Monday, November 16, 2009

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

1 comment:

  1. It won't work if c:\temp is a file or the current directory is not on disk c:

    ReplyDelete