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. The value of system variable &EXITRC also indicates whether the specified file exists.

Syntax: How to Determine If a File Exists Under Windows

[opsys] STATE filename

where:

opsys

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

filename

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. The variable &EXITRC has the value zero (0) if the file exists and the value 2 if the file does not exist. If the file does not exist, the following message is generated:

File doesn't exist