Question Lingnan Zhang · Sep 24, 2023

How to create a new directory using code

I want to create a folder directory through code, but I don't know how to write it

Product version: IRIS 2020.1

Comments

Ashok Kumar T · Sep 25, 2023

Hi @Lingnan Zhang 

You can use %File API class to create a directory. This result will be 1 if directory is created else 0. Refer the sample code below

set directory="c:\Test"write##class(%File).CreateDirectory(directory) ; result will be 1 if create else 0
0
Julius Kavay  Sep 25, 2023 to Lingnan Zhang

As an addition to the above said

set mydir="C:\dir1\dir2\newdir"//// creates newdir ONLY if dir1 and dir2 existswrite##class(%File).CreateDirectory(mydir)

// creates newdir and, IF NECESSARY, the intermediate directories dir2 and dir1 toowrite##class(%File).CreateDirectoryChain(mydir)
0