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.
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.
Have a look at the %File class and its queries (especially FileSet). This allows you to get the information you're looking for:
http://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?PAGE=CLASS&LIBRARY=%25SYS&CLASSNAME=%25Library.File
Check out this example:
s ret=##class(%File).FileSetExecute(.x,"C:\temp","*","",1)
f i=1:1 s ret=##class(%File).FileSetFetch(.x,.y) q:y="" s ^FileList(i)=y
s i=""
f d q:i=""
. s i=$o(^FileList(i)) q:i=""
. s mylist=^(i)
. i $list(mylist,2)="D" s dir=$list(mylist,1) w !,dir
. q
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 ListDir 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") }
Thanks, Fabian!
Also, would like to introduce again code guidelines we use in Russian office for Caché ObjectScript.