Determining If A File Exists Under Windows

How to:

The STATE command sets the system variable &RETCODE to a value that indicates whether a specified file exists.

Syntax: How to Determine If a File Exists Under Windows

[opsys] STATE filename



Identifies the operating environment. For Windows, the value can be WINNT or DOS.


Is the file whose existence you want to determine. It can be a file name in the current path, a full path name, or an application name and filename in the form appname/filename.

After issuing the command, the variable &RETCODE has the value zero (0) if the file exists and the value -1 if the file does not exist. If the file does not exist, the following message is generated:

File doesn't exist