Kbase P81349: How to check if a file exists using 4GL?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/21/2004 |
|
Status: Unverified
GOAL:
How to check if a file exists using 4GL?
FIX:
One way to test; in Progress 4GL; whether a file exists or not is to use the Progress 4GL SEARCH function as demonstrated in the following code snippet. The solution here assumes that we are looking for a file in the current Progress session PROPATH. To test for files that are not in the PROPATH, the file name ASSIGN statement needs to use the full path of such files:
DEFINE VARIABLE cExistingFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cNonExistingFileName AS CHARACTER NO-UNDO.
/* assign the names to an existing and a non existing files respectively */
ASSIGN
cExistingFileName = "ExistingFileName"
cNonExistingFileName = "NonExistingFileName".
IF SEARCH (cExistingFileName) <> ? THEN
MESSAGE "The file named " cExistingFileName " actually exists"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ELSE
MESSAGE "The file named " cExistingFileName " does not exist"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
IF SEARCH (cNonExistingFileName) <> ? THEN
MESSAGE "The file named " cNonExistingFileName " actually exists"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ELSE
MESSAGE "The file named " cNonExistingFileName " does not exist"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
Another way is to define a function that would return TRUE if the file exists and or FALSE otherwise as in the following code:
FUNCTION fileExists RETURNS LOGICAL (INPUT pcFileName AS CHARACTER).
IF SEARCH(pcFileName) <> ? THEN
RETURN TRUE.
ELSE
RETURN FALSE.
END FUNCTION.
DEFINE VARIABLE cExistingFileName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cNonExistingFileName AS CHARACTER NO-UNDO.
ASSIGN
cExistingFileName = "ExistingFileName"
cNonExistingFileName = "NonExistingFileName".
MESSAGE fileExists(cExistingFileName) fileExists(cNonExistingFileName)
VIEW-AS ALERT-BOX INFO BUTTONS OK.