4

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.

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
MrNeilP
  • 349
  • 1
  • 5
  • 19

2 Answers2

7

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.
Jensd
  • 7,886
  • 2
  • 28
  • 37
  • I have one doubt here. As SEARCH () function will search all propath directories, it will degrade performance of application. if we gave exact directory path with us , Can we search in a specific directory using search function or do we have other way to do same ? – MrNeilP Jul 01 '14 at 10:17
  • From the documentation: "If you provide a fully qualified pathname, SEARCH checks if the file exists. In this case, SEARCH does not search directories on the PROPATH." – Jensd Jul 01 '14 at 10:23
6

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).