Neutralino.filesystem
Neutralino.filesystem
namespace contains methods for handling files.
#
filesystem.createDirectory(path)Creates a directory or multiple directories recursively. Throws NE_FS_DIRCRER
if directory creation is
not possible.
#
Parameterspath
String: New directory path.
#
filesystem.remove(path)Removes a directory or file. If the given path is a directory, this function recursively removes all contents
of the specific directory. Throws NE_FS_REMVERR
if the removal is not possible.
#
Parameterspath
String: Directory or file path.
#
filesystem.writeFile(filename, data)Writes a text file. Throws NE_FS_FILWRER
for file write errors.
#
Parametersfilename
String: Filename.data
String: Content of the file.
#
filesystem.appendFile(filename, data)Appends text content to file. Throws NE_FS_FILWRER
for file write errors. If the provided file doesn't exist,
this function creates a new file with data
.
#
Parametersfilename
String: Filename.data
String: Content to append.
#
filesystem.writeBinaryFile(filename, data)Writes a binary file. Throws NE_FS_FILWRER
for file write errors.
#
Parametersfilename
String: Filename.data
ArrayBuffer: Content of the binary file as an ArrayBuffer.
#
filesystem.appendBinaryFile(filename, data)Appends binary data to a file. Throws NE_FS_FILWRER
for file write errors. If the provided file doesn't exist,
this function creates a new file with data
.
#
Parametersfilename
String: Filename.data
ArrayBuffer: Binary content to append as an ArrayBuffer.
#
filesystem.readFile(filename)Reads a text file. Throws NE_FS_FILRDER
for file read errors.
#
Parametersfilename
String: Filename.pos
Number (optional): File cursor position in bytes.size
Number (optional): File reader buffer size in bytes.
#
Return String (awaited):File content.
#
filesystem.readBinaryFile(filename)Reads binary files. Throws NE_FS_FILRDER
for file read errors.
#
Parametersfilename
String: Filename.pos
Number (optional): File cursor position in bytes.size
Number (optional): File reader buffer size in bytes.
#
Return Object (awaited):Content of the binary file as an ArrayBuffer.
#
filesystem.openFile(filename)Creates a readable file stream. Throws NE_FS_FILOPER
for file open errors.
#
Parametersfilename
String: Filename.
#
Return Number (awaited):File stream identifier.
#
filesystem.updateOpenedFile(id, action, data)Invokes file stream actions. Throws NE_FS_UNLTOUP
if the framework can't update the stream. Call this method
to read and seek an opened file (aka a readable stream).
#
Parametersid
Number: File stream identifier.action
String: An action to take. Accepts only the following values:read
: Reads a bytes segment from the file stream.readBinary
: Behaves the same asread
but uses the binary read mode.readAll
: Triggers theread
action until file stream cursor position reaches EOF.readAllBinary
: Behaves the same asreadAll
but uses the binary read mode.seek
: Sets the file cursor position.close
: Closes and frees file handler resources.
data
Object (optional): Additional data for theaction
. Send the buffer size in bytes (default: 256 bytes) if theaction
isread
,readBinary
,readAll
, orreadAllBinary
. Send the file stream cursor position if the action isseek
.
#
filesystem.getOpenedFileInfo(id)Returns file stream details. Throws NE_FS_UNLTFOP
if the file stream identifier is not valid.
#
Parametersid
Number: File stream identifier.
#
Return Object (awaited):id
Number: File stream identifier.eof
Boolean: Becomestrue
if the stream reached EOF.pos
Number: File stream cursor position.lastRead
Number: Last read bytes.
#
filesystem.createWatcher(path)Creates a filesystem watcher. Throws NE_FS_UNLCWAT
for watcher creation failures. If there is an existing
active watcher for the given path, this function returns the existing watcher identifier.
#
Parameterspath
String: Directory path.
#
Return Number (awaited):File watcher identifier.
#
filesystem.removeWatcher(watcherId)Removes a filesystem watcher. Throws NE_FS_NOWATID
for watcher removal failures.
#
ParameterswatcherId
Number: File watcher identifier.
#
Return Number (awaited):File watcher identifier.
#
filesystem.getWatchers()Returns information about created file watchers.
#
Return Object (awaited):An array of FileWatcher
objects.
#
FileWatcherid
Number: Watcher identifier.path
String: File watcher path.
#
filesystem.readDirectory(path, options)Reads directory contents. Throws NE_FS_NOPATHE
if the path doesn't exist.
#
Parameterspath
String: File/directory path.
#
optionsrecursive
Boolean: Read sub-directories recursively. The default value isfalse
.
#
Return Object (awaited):An array of DirectoryEntry
objects.
#
DirectoryEntryentry
String: file name.type
String: The type of the entry (FILE
orDIRECTORY
).
#
filesystem.copy(source, destination)Copies a file or directory to a new destination. Throws NE_FS_COPYERR
if the system cannot copy the path.
#
Parameterssource
String: Source path.destination
String: Destination path.
#
filesystem.move(source, destination)Moves a file or directory to a new destination. Throws NE_FS_MOVEERR
if the system cannot rename the path.
#
Parameterssource
String: Source path.destination
String: Destination path.
#
filesystem.getStats(path)Returns file statistics for the given path. If the given path doesn't exist or is inaccessible,NE_FS_NOPATHE
is thrown.
Therefore, you can use this method to check for the existance of a file or directory.
#
Parameterspath
String: File or directory path.
#
Return Object (awaited):size
Number: Size in bytes.isFile
Boolean:true
if the path represents a normal file.isDirectory
Boolean:true
if the path represents a directory.createdAt
Number: On Windows, returns Unix milliseconds of the file creation time — On Unix or Unix-like platforms, returns Unix milliseconds of the last inode modification time.modifiedAt
Number: Unix milliseconds of the last file modification time.