files

Contains functions for working with files

Constants

FILES_COMPARATOR : function = def(f1, f2) = compare(f1, f2)

function which compares two file descriptors

SDCARD : string Android = path to SDCARD

path to SDCARD

Functions

canExecute(f) - checks execute permission of the descriptor f

canRead(f) - checks read permission of the descriptor f

canWrite(f) - checks write permission of the descriptor f

copy(src, dst) - copies file src to dst location

delete(f) - removes file or directory. Returns 1 if delete was successfull, 0 otherwise

exists(f) - checks file or directory existing. Returns 1 if exists, 0 otherwise

fclose(f) - closes file

fileSize(f) - returns file size in bytes

flush(f) - flushes write buffer into file

fopen(path, mode = "r") - opens file файл with path in given mode:

  • "" - opens file or directory for getting info;

  • "r" - opens file for read in text mode;

  • "rb" - opens file for read in binary mode;

  • "w" - opens file for write in text mode;

  • "w+" - opens file for append in text mode;

  • "wb" - opens file for write in binary mode;

  • "wb+" - opens file for append in binary mode.

    Returns a file descriptor for using in other functions.

Example

f1 = fopen("text.txt") // opens file text.txt for read in text mode
f2 = fopen("E:/1.dat", "rbwb") // opens file 1.dat on drive E for binary read and write"

getParent(f) - returns parent path of the given descriptor f

isDirectory(f) - checks if descriptor f is directory

isFile(f) - checks if descriptor f is file

isHidden(f) - checks if descriptor f is hidden

lastModified(f) - returns last modification time

listFiles(f) - returns array with filenames in given directory.

f - directory descriptor

Example

f1 = fopen("E:/examples", "") // opens directory examples for getting information
list = listFiles(f1) // gets array with filenames in directory

mkdir(f) - creates the directory. Returns 1 if operation was successfull, 0 otherwise

mkdirs(f) - creates the directories. Returns 1 if operation was successfull, 0 otherwise

readAllBytes(f) - reads all bytes from file. Returns array with bytes

Example

f1 = fopen("file.bin", "rb")
array = readAllBytes(f1)

readBoolean(f) - reads boolean (1 byte). Returns 0 if byte was 0, 1 otherwise

readByte(f) - reads one byte

readBytes(f, array, offset = 0, length = length(array)) - reads length bytes of file f to array starting from offset. Returns number of readed bytes

Example

f1 = fopen("file.bin", "rb")
array = newarray(2048)
readedCount = readBytes(f1, array) // reads 2048 bytes
readedCount = readBytes(f1, array, 10) // reads 2048 bytes starting from 11 byte
readedCount = readBytes(f1, array, 20, 10) // reads 10 bytes, starting from 21 byte

readChar(f) - reads one char (2 bytes). Returns number char's code

readDouble(f) - reads 8 bytes double number

readFloat(f) - reads 4 bytes float number

readInt(f) - reads 4 bytes integer number

readLine(f) - reads line from file opened in text mode

readLong(f) - reads 8 bytes long number

readShort(f) - reads 2 bytes short number

readText(f) - reads all file's content as string

readUTF(f) - reads string in binary mode

rename(from, to) - renames (or moves) file

Example

f1 = fopen("C:/file1", "i")
f2 = fopen("E:/file2", "i")
rename(f1, f2)
fclose(f1)
fclose(f2)

setLastModified(f, time) - sets last modified time

setReadOnly(f) - marks descriptor read only

setExecutable(f, executable, ownerOnly = true) - sets execute permission

setReadable(f, readable, ownerOnly = true) - sets read permission

setWritable(f, writable, ownerOnly = true) - sets write permission

writeBoolean(f, v) - writes boolean (0 or 1) to file

writeByte(f, v) - writes one byte to file

writeBytes(f, array, offset = 0, length = length(array)) - writes length bytes to file f from byte array starting from offset

writeChar(f, v) - writes one char (2 bytes) to file. v can be number - writes number, or string - writes code of first symbol

writeDouble(f, v) - writes 8 bytes double number to file

writeFloat(f, v) - writes 4 bytes float number to file

writeInt(f, v) - writes 4 bytes integer number to file

writeLine(f, v) - writes string to file in text mode adds line break at the end of the string

writeLong(f, v) - writes 8 bytes long number to file

writeShort(f, v) - writes 2 bytes short number to file

writeText(f, v) - writes string to file in text mode. Unlike writeLine does not add line break

writeUTF(f, v) - writes string to file in binary mode

results matching ""

    No results matching ""