Closes an open file.
Example:
# Example for fclose
try
fp = fopen("/tmp/test.txt", "w")
fclose(fp)
catch err
println "File operation failed"
endtry
Check if open file cursor is at end-of-file
Example:
# Example for feof
try
write_file("/tmp/test.txt", "hello")
fp = fopen("/tmp/test.txt", "r")
println feof(fp)
fclose(fp)
catch err
println "File operation failed"
endtry
Flushes filehandle write buffer to disk.
Example:
# Example for fflush
try
fp = fopen("/tmp/test.txt", "w")
fwrite(fp, "hello")
fflush(fp)
fclose(fp)
catch err
println "File operation failed"
endtry
Returns the file mode attributes of a given file, or -1 on error.
Example:
# Example for file_mode
println file_mode("/etc/passwd")
println file_mode("/tmp")
Returns the file size, in bytes, of a given file string, or -1 if the file cannot be checked.
Example:
# Example for file_size
f = temp_file("za-size-")
write_file(f, "hello world")
println file_size(f)
println file_size("/etc/passwd")
Attempts to place a file lock on file_handle.
Lock type can be "r" (read), "w" (write) or "u" (unlock)
Returns true if the file could not be locked.
Example:
# Example for flock
fh = fopen("/tmp/za_flock.txt", "w")
flock(fh)
fclose(fh)
Opens a file and returns a file handle. mode can be either w (write), wa (write-append) or r (read).
Example:
# Example for fopen
try
fp = fopen("/tmp/test.txt", "w")
println fp
fclose(fp)
catch err
println "File operation failed"
endtry
Reads a string from an open file until delim is encountered (or end-of-file).
Example:
# Example for fread
try
write_file("/tmp/test.txt", "hello world")
fp = fopen("/tmp/test.txt", "r")
println fread(fp, 5)
fclose(fp)
catch err
println "File operation failed"
endtry
Move the current position of reads or writes to an open file.
relativity indicates where the offset is relative to.
(0:start of file,1:current position, 2:end of file) The newly sought position is returned.
Example:
# Example for fseek
write_file("/tmp/za_fseek.txt", "hello")
fh = fopen("/tmp/za_fseek.txt", "r")
fseek(fh, 0, 0)
The current read pointer position is returned.
Example:
# Example for ftell
try
write_file("/tmp/test.txt", "hello world")
fp = fopen("/tmp/test.txt", "r")
println ftell(fp)
fclose(fp)
catch err
println "File operation failed"
endtry
Writes a string to an open file.
Example:
# Example for fwrite
try
fp = fopen("/tmp/test.txt", "w")
println fwrite(fp, "hello")
fclose(fp)
catch err
println "File operation failed"
endtry
Returns true if file_name is a directory.
Example:
# Example for is_dir
println is_dir("/tmp")
println is_dir("/etc/passwd")
println is_dir("/nonexistent")
Returns true if file_name is a regular file.
Example:
# Example for is_file
println is_file("/etc/passwd")
println is_file("/tmp")
println is_file("/nonexistent")
Returns the file access permissions as an integer.
Example:
# Example for perms
println perms("/etc/passwd")
println perms("/tmp")
Returns the contents of the named file string, or errors.
Example:
# Example for read_file
f = temp_file("za-read-")
write_file(f, "hello world")
println read_file(f)
Returns a unix file stat structure containing underlying file information.
Example:
# Example for stat
println stat("/tmp")
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
write_file("/tmp/test.txt", "hello world")