Question
Victor Hugo Osp... · Apr 28, 2021

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:

 

Method GetSMSText(nhc As %String, servicio As %String, hospital As %String, telefono As %String) As %Stream
{
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)
}
...

<code name='Call SMS MedicoPeti' xpos='740' ypos='1050' >
<![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:

 

Method GetSMSText(nhc As %String, servicio As %String, hospital As %String, telefono As %String) As %Stream
{
// 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

Product version: Caché 2017.1
$ZV: Cache for Windows (x86-64) 2017.2.1 (Build 801_3U) Thu Apr 12 2018 10:02:23 EDT
00
2 0 5 63
Log in or sign up to continue

Replies

// If file exist

If ##class(%File).Exists("path/filename")

Regards,

Cedric

ClassMethod Size(file)
{
   if '##class(%File).Exists(file) quit -1
   quit ##class(%File).GetFileSize(file)
}

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.