IF EXIST Finds Hidden and System Files (77856)



The information in this article applies to:
    Microsoft MS-DOS operating system 5.0
    Microsoft MS-DOS operating system 5.0a
    Microsoft MS-DOS operating system 6.0
    Microsoft MS-DOS operating system 6.2
    Microsoft MS-DOS operating system 6.21
    Microsoft MS-DOS operating system 6.22

This article was previously published under Q77856

SUMMARY

The IF EXIST command finds system and hidden files. You may encounter a situation in which IF EXIST finds a file and then the specified action on that file fails. It is possible that the IF EXISTS command is finding a file with hidden or system attributes and the specified action fails on a hidden file.

MORE INFORMATION

To duplicate this problem, create a file called TEST.TXT and give the file system or hidden attributes using the ATTRIB command. Next, execute the following command:

if exist test.txt del test.txt

Upon execution, the above command will return

FILE NOT FOUND
Access Denied


The IF EXIST command finds the file even though it has a hidden attribute, but the DEL command does not recognize hidden or system files. The solution is to remove the system and/or hidden attributes. The IF EXIST command will then function correctly.

Modification Type: Major Last Reviewed: 5/12/2003
Keywords: KB77856