Project

General

Profile

Actions

File api SCOL » History » Revision 1

Revision 1/3 | Next »
iri, 12/17/2011 09:13 PM


File api SCOL

http://www.scolring.org/files/doc_html/file_system.html

Files must be relative at the active Scol partition.
There is not the close file function, Scol manage any I/O.

To open a file :

Read only :
_checkpack = fun [S] P
Write only :
_getmodifypack = fun [S] W

To read a file :

_getpack = fun [P] S

fun main ()=
  _showconsole;
  let _checkpack "myFolder/myFile.ext" -> pFile in
  if pFile == nil then
    _fooS "This file doesn't exist" 
  else
    _fooS _getpack pFile;
  0;;

To get the content line by line :

fun displayLines (list)=
  if list == empty then
    0
  else
    let hd list -> line in
    (
    _fooS line;
    displayLines tl list
    );;

fun main ()=
  _showconsole;
  let _checkpack "myFolder/myFile.ext" -> pFile in
  if pFile == nil then
  (
    _fooS "This file doesn't exist";
    1
  )
  else
    displayLines lineextr _getpack pFile;;

If you want the content word by word, you can do something similar with strextr instead of lineextr.

To get the size :

_fileSize = fun [P] I

fun main ()=
  _showconsole;
  let _checkpack "myFolder/myFile.ext" -> pFile in
  _fooId
     if pFile == nil then
       nil
     else
       _fileSize pFile;
  0;;

To write in a file :

_createpack = fun [S W] I
_appendpack = fun [S W] I
_storepack = fun [S S] I

fun main ()=
  _showconsole;
  let _getmodifypack "anyFolder/anyFile.ext" -> wFile in
  if 0 == _createpack "Bob and Alice " wFile then
    if 0 == _appendpack "are married !" wFile then
      _fooS "Done !" 
    else
      _fooS "_appendpack : error" 
  else
    _fooS "_createpack : error";
  0;;

Updated by iri about 13 years ago · 1 revisions