Crayon

AboutTutorialsDocumentationDemosDownloadSource

FileIO

Provides basic functions for interacting with the local file system.

enum TextEncoding[link]

Available text encodings for files. Used by FileIO functions.

NameDescription
UTF8

The UTF-8 encoding without a Byte-Order-Mark.

UTF8_BOM

The UTF-8 encoding with the Byte-Order-Mark.

UTF16

The UTF-16 encoding.

UTF32

The UTF-32 encoding.

ASCII

Basic ASCII encoding.

function currentDirectory()[link]

Returns the current directory that the app is running in.

function directoryCreate(path, makeParents)[link]

Creates a new directory

Arguments

NameTypeOptionalDescription
path string

an absolute or relative path to create

makeParents boolean Optional

true if parent directories should be created if already not present

function directoryDelete(path)[link]

Deletes a directory

Arguments

NameTypeDescription
path string

an absolute or relative path of a directory to delete

function directoryExists(path)[link]

Checks to see if a directory exists.

Arguments

NameTypeDescription
path string

an absolute or relative path

Return Value

TypeDescription
boolean

True if the path exists and is a directory (not a file).

function directoryList(path, includeFullPath)[link]

Returns a list of files and subdirectories in a given directory

Arguments

NameTypeOptionalDescription
path string

an absolute or relative path

includeFullPath boolean Optional

true if absolute file paths should be returned. Otherwise, file names only are returned.

Return Value

TypeDescription
List of strings

list of files

function directoryMove(pathFrom, pathTo)[link]

Moves a directory and its contents to a new location.

Arguments

NameTypeDescription
pathFrom string

an absolute or relative path of a directory to move

pathTo string

an absolute or relative path of a location to move a directory to

function fileCopy(pathFrom, pathTo, allowOverwrite)[link]

Copies a file to a new location. Optionally allows overwriting files.

Arguments

NameTypeOptionalDescription
pathFrom string

an absolute or relative path of the original file location

pathTo string

an absolute or relative path of the new file location

allowOverwrite boolean Optional

true if overwriting existing files is okay

function fileDelete(path)[link]

Deletes a file from disk

Arguments

NameTypeDescription
path string

an absolute or relative path

function fileExists(path)[link]

Checks to see if a file exists.

Arguments

NameTypeDescription
path string

an absolute or relative path

Return Value

TypeDescription
boolean

True if the path exists and is a file (not a directory).

function fileMove(pathFrom, pathTo, allowOverwrite)[link]

Moves a file from one location to a new one. Optionally allows overwriting files.

Arguments

NameTypeOptionalDescription
pathFrom string

an absolute or relative path of the original file location

pathTo string

an absolute or relative path of the new file location

allowOverwrite boolean Optional

true if overwriting existing files is okay

function fileReadBytes(path)[link]

Returns a list of bytes in the file. These are unsigned numbers from 0 to 255.

Arguments

NameTypeDescription
path string

an absolute or relative path

Return Value

TypeDescription
List of integers

List of bytes

function fileReadLines(path)[link]

Returns a list of lines in the file as a list of strings

Arguments

NameTypeDescription
path string

an absolute or relative path

Return Value

TypeDescription
List of strings

List of lines in the file

function fileReadText(path)[link]

Returns the file contents as a string

Arguments

NameTypeDescription
path string

an absolute or relative path

Return Value

TypeDescription
string

file contents as a string

function fileWriteBytes(path, bytes)[link]

Writes binary content to a file. Input must be a list of byte values that are either signed or unsigned.

Arguments

NameTypeDescription
path string

an absolute or relative path

bytes List of integers

List of bytes

function fileWriteText(path, content, encoding)[link]

Writes text to a file

Arguments

NameTypeOptionalDescription
path string

an absolute or relative path

content string

content to write to a file as a string

encoding FileIO.TextEncoding Optional

encoding to use

function getPathInfo(path)[link]

Returns a file descriptor.

Arguments

NameTypeDescription
path string

an absolute or relative path

Return Value

TypeDescription
FileIOCommon.FileDescriptor

File properties

function pathExists(path)[link]

Checks to see if a path exists (either a file or a directory).

Arguments

NameTypeDescription
path string

an absolute or relative path

Return Value

TypeDescription
boolean

True if the path exists.

function pathJoin(parts)[link]

Joins a list of strings with the platform's default path delimiter.

Arguments

NameTypeDescription
parts List of strings

strings to join