Cache Syntax - Directory Exists
I am trying to write some code to check to see if a directory exists before creating a new directory.
When I do the following I am not getting a response, but the directory exists..
do ##class(%File).DirectoryExists("/ensemble/")am I missing something?
Comments
How do you expect to get the response in your command?
If you read documentation carefully, you will find:
classmethod DirectoryExists(filename As %String) as %Boolean
Tests if filename is a directory. returns 1 if it is a directory, otherwise, returns 0.
So, you should set the result of this function to some value.
set result=##class(%File).DirectoryExists("/ensemble/")if I run it from the command line I was expecting for it to return me a 1. Is that not possible?
You aren't actually writing a response. To get the result in the terminal, you'd need to 'write' the output instead of 'do'.
I found by using %Library.File it worked better.
w ##class(%Library.File).DirectoryExists("/ensemble/")
1
w ##class(%Library.File).DirectoryExists("/ensemble/Scott/")
1
w ##class(%Library.File).DirectoryExists("/joe")
0
w ##class(%Library.File).DirectoryExists("/joe/")
0
Thanks for your help.
Did it work better than what?
Both classes are really the same one, as %Library is the default package name for %-classes.