File operations

File existence should be checked before writing to any path

appendFile
adds data at the end of a file
chmod
changes a file's permissions on the OS file system. use with care and only when needed.
copyFile
copies a single file
deleteFile
deletes a file from the OS file system
fileExists
check if a file exists on the system
fileWritable
check if a file path is writable or protected
findFile
searches a file on the OS file system
getFileBytes
check the amount of bytes of a file
getFileSHA256
Get a hex string representing the SHA256 of a file.
getPathInfo
get an object with basic details of a file path
readFile
load a complete file as string
readFileBase64
load a complete file as string in base64 encoding
renameFile
rename an existing file
revealPath
Open the given path in the OS finder/explorer to show to the user. (Added since core v0.4.1)
writeFile
writes/replaces data to a (new) file
writeFileBase64
write a complete file from a base64 encoded string

examples

// read and write text data to a file
function TestReadWriteFile()
{
    var filepath = folders.temp + gvar.pss + "scribble.txt";
    var contents = "testing 123 !";

    writeFile(filepath, contents); // writing to file
    echo(readFile(filepath)); // reading back contents

    appendFile(filepath, contents); // append to file add the test string again 
    echo(readFile(filepath)); // reading back contents

    deleteFile(filepath);
}

// load and save a file as base64 string. handy for handling raw data
function TestReadWriteFileBase64()
{
    var filename = openFileDialog("select a file to load as base64", folders.home, "");
    base64data = readFileBase64(filename); // loads all data as base 64 string

    var filename_out = saveFileDialog("select a save location", folders.output, "");
    writeFileBase64(filename_out, rawdata);
}

// Use a wildcard to find a test file in a folder
function TestFindFile()
{
    var filepath = folders.temp + gvar.pss + "scribble.txt";
    writeFile(filepath, "testing 123 !");

    var startfolder = folders.temp;
    var wildcardPattern = "scri*";

    var r = findFile(startfolder, wildcardPattern);
    for(var i=0; i < r.length; i++)
    {
        echo("found filepath " + i + ": " + r[i]);
    }
    deleteFile(filepath);
}

// create a file to copy and rename. and check if the file exists
function TestFileFunctions()
{
    var f1 = folders.output + "\\test1.txt";
    var f2 = folders.output + "\\test2.txt";
    var f3 = folders.output + "\\test3.txt";
    
    echo("writeFile: " + writeFile(f1, "test"));
    echo("copyFile: " + copyFile(f1, f2));
    echo("renameFile: " + renameFile(f2, f3));
    echo("fileExists: " + fileExists(f3));
    echo("fileWritable: " + fileWritable(f3));
}