To check whether a filename or folder name entered by a user exists or not, on a Windows environment, you may find this function useful.
It has a limit of 228 characters for the full path and name.
This limit could be removed by writing the “if exist” check to a batch file and then executing the batch file, but that approach needs one of the 1-32 work file numbers to be consistently available or passed as a parameter, which is messy. It is also slower, and we don’t need such long filenames at our site.
* Function : FILEXIST(<work>) * * Action : Returns TRUE if the work file or folder exists * * Parameter : Work file name (A1-228) * * NB! Max file name length is 228 characters, or NAT1308 results * DEFINE FUNCTION FILEXIST RETURNS (L) DEFINE DATA PARAMETER 1 #FILE (A253) BY VALUE /* Allow >228 to trigger NAT1308 via EXAMINE REPLACE LOCAL 1 #SHCMD (A253) INIT <'CMD /C if exist ' - H'222522' - ' exit 1'> END-DEFINE EXAMINE #SHCMD FOR H'25' REPLACE FIRST #FILE CALL 'SHCMD' #SHCMD 'NOSCREENIO' /* (SHCMD spares 11 more chars for #file than USR1052N) IF RET('SHCMD') = 1 FILEXIST := TRUE ELSE FILEXIST := FALSE END-IF END-FUNCTION END