Function: directory_exists

Check if a directory in the file system exists or not. Can be used to conditionally create directories before putting files in them, for example.

Prototype:


bool z = directory_exists ( string path ); 

Parameters:

Parameter name Type Description
path string path to directory, without a trailing slash (/)

Return value: Type Bool : True if the directory exists, otherwise false.

Example:

string dir = "/users/ole/Desktop/MyLoggFiles", res; 
if ( ! directory_exists ( dir)) then 
    res = create_directory ( dir ); 
end if
// Put some log file in it. 
string loggfile = dir + "/logfile.txt"
int x = open ( loggfile, "wa" ); 
write ( x, format ("%s Some log text...", string(now(), "yyyy-mm-dd" )));
close ( x ); 

See also: