Return to index

file functions

fclose(filehandle)

top

Closes an open file.

Example:

# Example for fclose
var f=fopen("/tmp/file","r")
fclose(f)


bool = feof(filehandle)

top

Check if open file cursor is at end-of-file

Example:

# Example for feof
f=fopen("/tmp/file","r")
println feof(f)
fclose(f)


position = fflush(filehandle)

top

Flushes filehandle write buffer to disk.

Example:

# Example for fflush
println fflush(f)


file_mode = file_mode(file_name)

top

Returns the file mode attributes of a given file, or -1 on error.

Example:

# Example for file_mode
println file_mode("/tmp/file")  # e.g., 33188


integer = file_size(string)

top

Returns the file size, in bytes, of a given file string, or -1 if the file cannot be checked.

Example:

# Example for file_size
println file_size("/tmp/f")


error_bool = flock(file_handle[,lock_type])

top

Attempts to place a file lock on file_handle.[#SOL]Lock type can be "r" (read), "w" (write) or "u" (unlock)

[#SOL]Returns true if the file could not be locked.


filehandle = fopen(filename,mode)

top

Opens a file and returns a file handle. mode can be either w (write), wa (write-append) or r (read).

Example:

# Example for fopen
var f=fopen("/tmp/file","r")
println f


string = fread(filehandle,delim)

top

Reads a string from an open file until delim is encountered (or end-of-file).

Example:

# Example for fread
f=fopen("/tmp/file","r")
println fread(f,"\n")
fclose(f)


position = fseek(filehandle,offset,relativity)

top

Move the current position of reads or writes to an open file.

[#SOL]relativity indicates where the offset is relative to.

[#SOL](0:start of file,1:current position, 2:end of file) The newly sought position is returned.

Example:

# Example for fseek
var f=fopen("/tmp/file","r")
println fseek(f,10,0)


position = ftell(filehandle)

top

The current read pointer position is returned.

Example:

# Example for ftell
var f=fopen("/tmp/f","r")
println ftell(f)


fwrite(filehandle,string)

top

Writes a string to an open file.

Example:


bool = is_dir(file_name)

top

Returns true if file_name is a directory.

Example:

# Example for is_dir
println is_dir("/tmp")  # true


bool = is_file(file_name)

top

Returns true if file_name is a regular file.

Example:

# Example for is_file
println is_file("/tmp/file")  # true


int = perms(file_name)

top

Returns the file access permissions as an integer.

Example:

# Example for perms
println perms("/tmp")  # e.g., 16877


string = read_file(string)

top

Returns the contents of the named file string, or errors.

Example:

# Example for read_file
println read_file("/etc/hostname")


stat_struct = stat(file_name)

top

Returns a unix file stat structure containing underlying file information.


bool = write_file(filename,wstring[,mode_number_or_string])

top

Writes the contents of wstring to file filename. Optionally sets the file permissions on new files. Returns true on success.

Example:

# Example for write_file
println write_file("/tmp/f","hi",0644)