Article ID: 65994 - View products that this article applies to.
This article was previously published under Q65994
You can use the IF EXIST statement to check for the presence of a directory. For example, to test for C:\WIN and then change to C:\WIN if it exists, use the following batch file:
C: IF NOT EXIST C:\WIN\NUL GOTO NOWINDIR CD \WIN :NOWINDIR
NUL always exists on a local MS-DOS FAT drive; therefore, if C:\WIN exists, C:\WIN\NUL exists. This technique can also be used to verify that a drive exists. For example:
If an unformatted disk is tested, or if the floppy disk drive is empty, an INT 24 error (Abort, Retry, Fail?) occurs.
IF EXIST E:\NUL GOTO USE_E
Neither of these tests works correctly with network devices or any other device that does not have a block device-driver-controlled FAT file system (for example, when you are using Windows for Workgroups 3.11 with 32-Bit File Access enabled).
Prior to using this technique, you should know what network software the client is using, what type of server they're connecting to, and the file system the server is using.
The following table shows when IF EXIST returns NUL:
With 32-Bit File No 32-Bit With 32-Bit Access and NetWare Drive Type File Access File Access 3.x connectivity Local FAT correctly always never Windows for Workgroups FAT correctly always never Microsoft LAN Manager HPFS never always never Windows NT FAT/NTFS never always never NetWare correctly never never
Article ID: 65994 - Last Review: November 16, 2006 - Revision: 2.1
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.