- → Examples - Go back to examples
Example 1 - NARS2000 User APL Function: FileSize Uses System Functions/Variables: ⎕NTIE ⎕NSIZE ⎕NUNTIE ⎕ELX
lNumBytes←FileSize strFileName;iTieNum;iRet
⍝Returns file size in bytes. If file does not exist, returns -1
⍝Sample call: FileSize "C:/FileName.txt"
⎕ELX←"→ErrFileSiz" ⍝On error(e.g. file not found), goto ErrFileSiz line
iTieNum←strFileName ⎕NTIE 0 ⍝Open file as if for reading, obtain tie number
lNumBytes←⎕NSIZE iTieNum ⍝Read in file size, normal operation, file found
iRet←⎕NUNTIE iTieNum ⍝Finished with file read, close/untie file #
⎕ELX←"⎕DM" ⍝Reset error execute function - to its default value
→0
ErrFileSiz: lNumBytes←-1 ⍝On error, program branches here; sets # bytes found to -1
⎕ELX←"⎕DM" ⍝Reset error execute function - to its default value
→0
|
See Also: System Functions - Quad NNames, Quad ELX