How to check the file existence or file size inside a method (BPL)
Hello all,
I'm a newcomer in ObjectScript and Ensemble and I would like to ask for any help.
I have a method which is called inside a BPL in order to create or append some data in a file by an operation. This is the current code:
{
quit ..SMSOperation_"##" _ hospital _"##" _ $ZDATE($H,4) _ "##" _ $piece($ZDATETIME($HOROLOG,3)," ",2) _ $char(13,10) _
telefono _ "##La interconsulta del paciente con numero de historia: " _nhc _" ha sido resuelta por el servicio: "_ servicio _"##" _ $char(13,10)
}
...
<![CDATA[ Set tRequest = ##class(Ens.StreamContainer).%New()
Set tRequest.Stream = ##class(%Stream.GlobalCharacter).%New()
Do tRequest.Stream.Write(process.GetSMSText(request.Paciente.nhc, request.Pedido.unidad.cod, request.Mensaje.centro, context.InterconsultaInfo.TelefonoMedicoPeti))
Set tSC = process.SendRequestAsync(process.TargetConfigName,tRequest, 0)]]>
</code>
What I would need to do now is to change the method in a way that check first the file existence or file size:
{
// check if the file exist or is not empty
if ("path/filename" ∄ || filesize = 0){
quit ..SMSOperation_"##" _ hospital _"##" _ $ZDATE($H,4) _ "##" _ $piece($ZDATETIME($HOROLOG,3)," ",2) _ $char(13,10) _
telefono _ "##La interconsulta del paciente con numero de historia: " _nhc _" ha sido resuelta por el servicio: "_ servicio _"##" _ $char(13,10)
} else {
quit ..SMSOperation_telefono _ "##La interconsulta del paciente con numero de historia: " _nhc _" ha sido resuelta por el servicio: "_ servicio _"##" _ $char(13,10)
} }
How could I put the condition in the if conditional please.
Thanks in advance for the help.
Bes regards,
Victor
If ##class(%File).Exists("path/filename")
Regards,
Cedric
Returnvalues:
-1=File does not exists, 0...n=Filesize
To clarify, are you looking for a method to be used in a Business Process to obtain the path and name of a file created by a Business Operation?
Hi Jeffrey, the method that I have in the BPL is currently sending a Stream to a process (EnsLib.File.PassthroughOperation class). All that I need to do now is put like a header in the first line of the file.
Hello guys, thanks for your prompt reply. I've tested and it works properly.