Testing If a Drive or Directory Exists from a Batch File

This article was previously published under Q65994
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.
SUMMARY
You can use the IF EXIST statement to check for the presence of adirectory. For example, to test for C:\WIN and then change to C:\WIN if itexists, use the following batch file:
   C:   IF NOT EXIST C:\WIN\NUL GOTO NOWINDIR   CD \WIN   :NOWINDIR				
MORE INFORMATION
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 driveexists. For example:
   IF EXIST E:\NUL GOTO USE_E				
If an unformatted disk is tested, or if the floppy disk drive is empty, anINT 24 error (Abort, Retry, Fail?) occurs.

Neither of these tests works correctly with network devices or any otherdevice 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-BitFile Access enabled).

Prior to using this technique, you should know what network software theclient is using, what type of server they're connecting to, and the filesystem 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 NetWareDrive Type                  File Access   File Access    3.x connectivityLocal FAT                    correctly      always            neverWindows for Workgroups FAT   correctly      always            neverMicrosoft LAN Manager HPFS     never        always            neverWindows NT FAT/NTFS            never        always            neverNetWare                      correctly      never             never				
3.20 3.21 3.30 3.30a 4.00 4.01 5.00 5.00a 6.00 6.20 6.21 6.22 vfat lanman true false positive negative
Properties

Article ID: 65994 - Last Review: 11/16/2006 05:37:19 - Revision: 2.1

Microsoft MS-DOS 3.1, Microsoft MS-DOS 3.2 Standard Edition, Microsoft MS-DOS 3.21 Standard Edition, Microsoft MS-DOS 3.3 Standard Edition, Microsoft MS-DOS 3.3a, Microsoft MS-DOS 4.0 Standard Edition, Microsoft MS-DOS 4.01 Standard Edition, Microsoft MS-DOS 5.0 Standard Edition, Microsoft MS-DOS 5.0a, Microsoft MS-DOS 6.0 Standard Edition, Microsoft MS-DOS 6.2 Standard Edition, Microsoft MS-DOS 6.21 Standard Edition, Microsoft MS-DOS 6.22 Standard Edition, Microsoft Windows for Workgroups 3.11

  • KB65994
Feedback