The File object represents a file or directory on disk and can be used to navigate / access the file system from HISEScript.
In order to use it, call the Filesystem API class to get a folder from where you navigate to the file you want to modify / load.
Be aware that there is no possibility of writing / loading files using absolute paths (eg.
) because it is not portable across operating systems (and even computers).
Returns the new directory created at the file location, if directory doesn't already exist
Deletes the file or directory WITHOUT confirmation.
Extracts the ZIP archive if this file is a .zip file.
File.extractZipFile(var targetDirectory, bool overwriteFiles, var callback)
This method will extract a standard ZIP file (without password protection) to the given target directory (which can be either a file path String or a File object).
The extraction process will be executed on the sample loading thread and you can assign a callback that is executed to track the extraction progress.
The callback expects a single parameter that will contain a JSON object with the following properties:
||String||The target directory as file path.|
||String||A error message if something went wrong during extracting.|
||double||the progress from 0.0 to 1.0. Be aware that this tracks only the number of files extracted vs. the total number of files, so if you have one big file inside the archive, it will not work.|
||int||the number of bytes that have been extracted.|
||String||the relative path of the file that is currently being extracted.|
||int||a status flag indicating the state of the extraction:
The callback will be executed at the beginning of the extraction (with the Status flag
) and at the end (with the Status flag
) as well as when an error occurs.
If you extract a small archive (less than ~400 files), the callback will also be executed for each file (this limit prevents the scripting queue to be clogged with huge archives).
Returns a child file if this is a directory.
Returns the parent directory as File.
Checks if this file exists and is a directory.
Checks if this file exists and is a file.
Loads the given file as object.
This tries to parse the given file as JSON object and return it. If you are storing complex data, this will be the most convenient option.
Loads the given file as text.
Loads the encrypted object using the supplied RSA key pair.
This function will load a JSON object from a file that has been written with File.writeEncryptedObject()
The encryption uses Blowfish encryption, so it should be able to encrypt / decrypt pretty fast.
You can use these functions to create an authentification scheme that stores the license key in a file in order to bypass online activation.
Opens a Explorer / Finder window that points to the file.
This opens a OS specific file browser that will reveal the file to the user.
Returns a String representation of that file.
You can use this to display the filename on your UI.
argument is expected to be one of the constants supplied in the
The following table will show the formatting for the file
Writes the given data (either a Buffer or Array of Buffers) to a audio file.
File.writeAudioFile(var audioData, double sampleRate, int bitDepth)
Encrypts an JSON object using the supplied key.
File.writeEncryptedObject(var jsonData, String key)
This function will encrypt the JSON object with the given key and write it to the specified file. The key can be up to 72 characters long.
In order to read the encrypted file, use File.loadEncryptedObject()
with the same key.
Replaces the file content with the JSON data.
Replaces the file content with the given text.
It will return
if the file operation was completed successfully or
if there was an error during the operation.