COMANDO $ZF

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.

hugs

Davidson

Answers

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")

Dmitry, Thanks for the help, perfect.

With this class is it possible to copy and move files as well? If possible send me how to make the file copy enters folders and also move file from one folder to another.
Thank you

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

Regards

Manel

$zu(68,40,switch)

can be replaced with:

set old=$system.Process.SetZEOF(switch)

Also, what does this command do?

kill ^TMP($zn,$j)

The original author is storing the output of the command into a temporary global ^TMP.
$ZN is the routine name of his tool.
$J is the job number or Process ID of the job running.
The command:  kill ^TMP($ZN,$J) is cleaning up things making sure he starts with a empty global.

Comments

Hi Davidson

Please note $zf(-1 is now depreciated as of the most recent releases/patches of Caché

The replacement is $zf(100 - but stressing this will only work on the most recent patches

Peter