Check if a Directory Exists

How do you check if a directory exists on the application server?

The following code is one way I've found. It uses the FindFiles function to return an array of subdirectories (matching on the * wildcard) &aSubDirs in a base directory &sBaseDir. It then loops through all the subdirectories and compares them to the check directory (&sCheckDir). Note that in this example, I am using absolute file paths. This should work on both NT and Unix servers…

Local array of string &aSubDirs;
Local string &sBaseDir;
Local string &sCheckDir;
Local boolean &bDirExists = False;
Local integer &i;
&sBaseDir = "C:\TEMP";
&sCheckDir = "C:\TEMP\TEST";
/* Get all the directories under the base directory &sBaseDir (C:\TEMP) */
&aSubDirs = FindFiles(&sBaseDir | "*", %FilePath_Absolute);
/* Loop through sub-directories and check if any of them match the directory &sCheckDir (C:\TEMP\TEST) */
For &i = 1 to &aSubDirs.Len
    If &aSubDirs[&i] = &sCheckDir Then
        &bDirExists = True;
If &bDirExists = True Then
    /* The directory exists */
    /* The directory does not exist */
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License