Article
· Sep 29, 2016 1m read

Cache - Checking If a Directory or File Exists

Checking if Directory or File Exists:

Outlined below is an example of how to check if a directory exists:

Set directoryName="c:\temp\nosuchdir"

/* Check for existence of a directory - Return Value:  0 - directory does not exist;  1 - directory does exist  */

Set directoryExists=##class(%File).DirectoryExists(directoryName)

If ('directoryExists)  // do the processing for when a directory does not exist


Outlined below is an example of how to check if a file exists:

Set fileName="a_test_filename.txt"

/* Check for existence of a file- Return Value:  0 - filename does not exist;  1 - filename does exist  */

Set fileExists=##class(%File).Exists(fileName)

If ('fileExists)  // do the processing for when a filename does not exist
Discussion (1)0
Log in or sign up to continue