Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if file exists

Status
Not open for further replies.
Mar 9, 2006
93
CA
In progress (9.1e) how do you check if the following file exists, c:\temp\customer.txt. Does anyone know how to do this?
Thanks
Matt
 
Here's how I did that for a file named 'banner.dat':

Code:
 DEF VAR v-banner-test AS CHARACTER EXTENT 6 FORMAT "x(76)" NO-UNDO.
INPUT THROUGH DIR banner.dat NO-ECHO.
           SET v-banner-test[1].
           SET v-banner-test[2].
           SET v-banner-test[3].
           SET v-banner-test[4].
           SET v-banner-test[5].
           SET v-banner-test[6].
           INPUT CLOSE.
           IF v-banner-test[6] MATCHES "*banner*" THEN DO:
               /* do stuff here when banner.dat exists */
           END.

This works because line 6 of the DIR command output will have either 'FILE NOT FOUND' or it will contain the filename.
 
Here's a very different method ...
Code:
ASSIGN FILE-INFO:FILE-NAME = "c:\temp\customer.txt".
IF NOT FILE-INFO:FILE-TYPE BEGINS "F" THEN
    MESSAGE "Not a file".

Cheers, Mike.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top