(Originally posted on Intersystems CODE by @Eduard Lebedyuk, 10/12/15) The following code snippet outputs all filenames in the file path "dir" in the Cache/IRIS terminal. The class method "test" runs the code:
Class eduardlebedyuk.filenamesInDir Extends %RegisteredObject
{
classmethod test() {
// replace dir with file path you want
set dir = "D:\directory"
set dir = ##class(%File).NormalizeDirectory(dir)
set file=$ZSEARCH(dir_"*")
while file'="" {
write !,file
set file=$ZSEARCH("")
}
}
}