Check if a file or folder exists
1 January 2000 by Snakefoot | Comment » | Trackback OffIt can be useful in batch files to know whether a file or folder exists. One can use files as semaphores and for inter proces communication (IPC).
To check if a file exists:
To check if a file exists:
To check if a directory exists (Notice the nul):IF EXIST c:\windows\win.com ECHO File exists!
Note if working with long directory names with spaces, then one needs to put quotes around the directory-/file-path (Notice that nul should not be included):IF EXIST c:\windows\nul ECHO Directory exists!
More Info MS KB Q65994IF EXIST "C:\Program Files\" ECHO Directory exists!
Updated: 23 July 2009
Comment by Frank - 23 July 2009 @ 19:13 Reply
This “\NUL” folder syntax is not working for me on XPsp2.