· Jun 21, 2018


Hello everyone

I have a problem with $ ZF (-1)

I need to delete file from windows folder example c: \ sys \ text.txt, when executing the w $ zf (-1, "c: \ sys \ text.txt") command, the file does not delete.
There is some other cache command that performs this task.



Discussion (8)1
Log in or sign up to continue

Function $zf(-1) just executes a command passed as the second argument, you passed only file name. it is not complete, you should add command del  for Windows.

set status = $zf(-1, "del c:\sys\text.txt")

it should return 0 if the command was successful.

If you want just delete a file, you can use %File class, useful for many different operations with files and folders.

set result = ##class(%File).Delete("c:\sys\text.txt")

Another option is to use the open command where first argument is the OS command. Then you can get the answer from OS. For example:

 set old=$zu(68,40,1) ; Enable $zeof

 kill ^TMP($zn,$j)
 set cmd="find /logs/* -printf '%Td/%Tm/%TY %f\n'"

 open cmd:"Q"
 use cmd for x=1:1 read line quit:$zeof=-1 set ^TMP($zn,$j,"FILE",x)=line
 close cmd

 if $zu(68,40,old) // Restore previous mode