From 1a34ce213a367c9c5b75969d69a59cd435fc3a96 Mon Sep 17 00:00:00 2001 From: CF Mitrah Date: Wed, 6 Mar 2024 21:00:16 +0530 Subject: [PATCH] Added a example for FileIsEOF() function --- .../01.functions/fileiseof/_examples.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/03.reference/01.functions/fileiseof/_examples.md b/docs/03.reference/01.functions/fileiseof/_examples.md index 8bd5a1748..f2fce4fdc 100644 --- a/docs/03.reference/01.functions/fileiseof/_examples.md +++ b/docs/03.reference/01.functions/fileiseof/_examples.md @@ -1 +1,16 @@ -*There are currently no examples for this function.* +```luceescript +filePath = "/path/to/file.txt" +openFile = fileopen(filePath, "read"); +lines = []; +// IMPORTANT: must close file, use try/catch/finally to do so +try { + // fileIsEOF(openFile) == false until we've read in the last line. + while( !fileIsEoF(openFile) ) { + arrayAppend(lines, fileReadLine( openFile )); + } +} catch(any e) { + rethrow; +} finally { + fileClose(openFile); +} +``` \ No newline at end of file