Examples/Files

From NARS2000
Revision as of 21:00, 25 January 2015 by Robert Wallick (talk | contribs) (Examples - Working with Files)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
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