Difference between revisions of "Working with Files and File Systems in Lianja"
From Lianjapedia
Yvonne.milne (Talk | contribs) |
m (Text replace - "Recital" to "Lianja") |
||
Line 1: | Line 1: | ||
− | ==Working with Files and File Systems in | + | ==Working with Files and File Systems in Lianja== |
− | ===Handling Text Files in | + | ===Handling Text Files in Lianja=== |
− | + | Lianja includes functions allowing text files to be created, opened and closed and their contents to be read, overwritten or appended to. | |
− | ====Opening and Creating Text Files in | + | ====Opening and Creating Text Files in Lianja==== |
* [[FCREATE()|fcreate()]] - create a new text file, returning a file handle | * [[FCREATE()|fcreate()]] - create a new text file, returning a file handle | ||
Line 29: | Line 29: | ||
|} | |} | ||
− | ====Closing Text Files in | + | ====Closing Text Files in Lianja==== |
* [[FCLOSE()|fclose()]] - close a text file opened with [[FOPEN()|fopen()]] or [[FCREATE()|fcreate()]] | * [[FCLOSE()|fclose()]] - close a text file opened with [[FOPEN()|fopen()]] or [[FCREATE()|fcreate()]] | ||
Line 37: | Line 37: | ||
</pre> | </pre> | ||
− | ====Writing to a Text File using | + | ====Writing to a Text File using Lianja==== |
* [[FPUTS()|fputs()]] - write a character string to a text file, returning the number of bytes written | * [[FPUTS()|fputs()]] - write a character string to a text file, returning the number of bytes written | ||
Line 45: | Line 45: | ||
</pre> | </pre> | ||
− | ====Reading From a Text File using | + | ====Reading From a Text File using Lianja==== |
* [[FGETS()|fgets()]] - read and return a line from a text file | * [[FGETS()|fgets()]] - read and return a line from a text file | ||
Line 84: | Line 84: | ||
</code> | </code> | ||
− | ===Checking Whether a File Exists in | + | ===Checking Whether a File Exists in Lianja=== |
* [[FILE()|file()]] - check whether a file exists | * [[FILE()|file()]] - check whether a file exists | ||
Line 91: | Line 91: | ||
</pre> | </pre> | ||
− | ===Moving, Copying and Deleting Files with | + | ===Moving, Copying and Deleting Files with Lianja=== |
* [[RENAME|rename]] - move a file | * [[RENAME|rename]] - move a file | ||
Line 116: | Line 116: | ||
</pre> | </pre> | ||
− | ===Accessing File Attributes in | + | ===Accessing File Attributes in Lianja=== |
* [[FILEINFO()|fileinfo()]] - return a comma-separated string containing information about a file | * [[FILEINFO()|fileinfo()]] - return a comma-separated string containing information about a file | ||
Revision as of 01:41, 9 December 2012
Contents
Working with Files and File Systems in Lianja
Handling Text Files in Lianja
Lianja includes functions allowing text files to be created, opened and closed and their contents to be read, overwritten or appended to.
Opening and Creating Text Files in Lianja
- fcreate() - create a new text file, returning a file handle
numeric = fcreate(<filename as character>)
- fopen() - open an existing text file, returning a file handle
numeric = fopen(<filename as character> [, <mode as numeric>])
Mode | Description |
---|---|
If not specified, read-only | |
0 | Read-only |
1 | Write only. Existing contents are deleted. |
2 | Append. Text may be added to the end of the existing contents. |
Closing Text Files in Lianja
logical = fclose(<filehandle as numeric>)
Writing to a Text File using Lianja
- fputs() - write a character string to a text file, returning the number of bytes written
numeric = fputs(<filehandle as numeric>, <string as character> [, <bytes as numeric> [, <endofline as character>]])
Reading From a Text File using Lianja
- fgets() - read and return a line from a text file
character = fgets(<filehandle as numeric> [, <bytes as numeric> [, <endofline as character>]])
- feof() - evaluate if the record pointer is at the end of file marker
logical = feof(<filehandle as numeric>)
Example
open database southwind use example fp=fcreate("names.txt") count=0 do while not eof() count = count + fputs(fp,trim(last_name) + ", "+trim(first_name)) skip enddo fclose(fp) echo str(count,5) + " bytes written.\n" fp = fopen("names.txt") count = 0 do while not feof(fp) if left(fgets(fp),5) = "Smith" ++count endif enddo fclose(fp) echo str(count,5) + " Smiths found.\n" close databases
Checking Whether a File Exists in Lianja
- file() - check whether a file exists
logical = file(<filename as character>)
Moving, Copying and Deleting Files with Lianja
- rename - move a file
rename <sourcefile as character> [to] <targetfile as character>
- copy file - copy a file
copy file <sourcefile as character> [to] <targetfile as character>
- erase - delete a file or files
erase <filename as character [, filename as character [, ...]]>
- delete file - delete a file
delete file <filename as character>
Accessing File Attributes in Lianja
- fileinfo() - return a comma-separated string containing information about a file
character = fileinfo(<filename as character>)
- fsize() - return the size of a file
numeric = fsize(<filename as character>)
- fdate() - return the last modification date of a file
date = fdate(<filename as character>)
- ftime() - return the last modification time of a file
character = ftime(<filename as character>)
- fullpath() - return the full path of a file
character = fullpath(<filename as character>)
- basename() - return the base filename of a file
character = basename(<filename as character>)
Miscellaneous File and File System Commands and Functions
- diskspace() - return the available space on the current disk
numeric = diskspace()