Working with Files and File Systems in Recital
From Recital Documentation Wiki
Revision as of 13:03, 25 January 2010 by Yvonnemilne (Talk | contribs)
Contents
Working with Files and File Systems in Recital
Handling Text Files in Recital
Recital 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 Recital
- 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 Recital
logical = fclose(<filehandle as numeric>)
Writing to a Text File using Recital
- 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 Recital
- fgets() - read and return a line from a text file
character = fgets(<filehandle as numeric> [, <bytes as numeric> [, <endofline as character>]])
Examples
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() if fgets(fp,5) = "Smith" ++count endif enddo fclose(fp) echo str(count,5) + " Smiths found.\n" close databases
Checking Whether a File Exists in Recital
- file() - check whether a file exists
logical = file(<filename as character>)
Moving, Copying and Deleting Files with Recital
- 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 Recital
- 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
- adir() - return number of files matching a pattern and load filenmames and information into arrays
numeric = adir(<skeleton as character> [, <filenames as array> [, <filesizes as array> [, <creationdates as array> [, <creationtimes as array> [, <attributes as array>]]]]])
- dir - display a directory of files
dir [<skeleton as character>]
- filecount()- return number of files matching a pattern
numeric = filecount(<skeleton as character>)
- curdir() - return name of the current directory
character = curdir()
- default()- return name of the current directory
character = default()
- set default - set current directory
set default to [<directory as character>]
- path() - return current Recital path setting
character = path()
- set path - set Recital path
set path to [<directories as character>]
- diskspace() - return the available space on the current disk
numeric = diskspace()