Question

How to check existance of particular file by use of code. Eg. def var a as character. a = "abc.p"

run value(a). ---> here first i want to check if abc.p exist in workspace or not.

Was it helpful?

Solution

You can use the SEARCH function. Directly from the online manual:

SEARCH function Searches the directories and libraries defined in the PROPATH environment variable for a file. The SEARCH function returns the full pathname of the file unless it is found in your current working directory. If SEARCH does not find the file, it returns the Unknown value (?).

Syntax

SEARCH ( opsys-file ) 

opsys-file

A character expression whose value is the name of the file you want to find. The name can include a complete or partial directory path. If opsys-file is a constant string, you must enclose it in quotation marks (" "). The value of opsys-file must be no more than 255 characters long.

Example:

DEFINE VARIABLE cPgm AS CHARACTER   NO-UNDO.

cPgm = "test.p".

IF SEARCH(cPgm) <> ? THEN 
    RUN VALUE(cPgm).
  • If you provide a fully qualified pathname, SEARCH checks if the file exists. In this case, SEARCH does not search directories on the PROPATH.

OTHER TIPS

If you do not want to use the propath you can use the FILE-INFO system handle.

After setting FILE-NAME, you can check the FILE-TYPE if it exists. See also the Progress Help for FILE-INFO.

FILE-INFO:FILE-NAME = a.
IF FILE-INFO:FILE-TYPE MATCHES "*F*"
THEN RUN VALUE(FILE-INFO:FULL-PATHNAME).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top