How to get folder list in the hosting OS from Caché


Hi All,
How to get the only folders (with sub-folder)from the particular drive using cache.
We need to create the only folders from some drive using Cache.

  • 0
  • 0
  • 430
  • 2
  • 2


Check out this example:

ListDir ;
  s ret=##class(%File).FileSetExecute(.x,"C:\temp","*","",1)
  f i=1:1 ret=##class(%File).FileSetFetch(.x,.y) q:y=""  ^FileList(i)=y
  s i=""
  f  d  q:i=""
  . i=$o(^FileList(i)) q:i=""
  . mylist=^(i)
  . $list(mylist,2)="D" dir=$list(mylist,1) !,dir
  . q

Please note that this example uses the old (deprecated) dot-syntax for the loop. It also loops through your data twice. Nowadays you would write the same more like this:

#include %occInclude
 set statement=##class(%SQL.Statement).%New()
 set status=statement.%PrepareClassQuery("%File","FileSet")
 if $$$ISERR(status) { do $system.OBJ.DisplayError(status) }
 set resultset=statement.%Execute("c:\temp","*","",1)
 while resultset.%Next() {
    write:resultset.%Get("Type")="D" !, resultset.%Get("Name")