Tools for EventScripter

System function: overwriteFile()

Description

overwriteFile(string file, string content) : bool

Overwrites a file. Deletes it first if it already exist.
Returns true on success, otherwise false.

Example

overwriteFile(JD_HOME + "/eventscripter/my-file-to-overwrite.txt", "Hello world");

Sourcecode

JD_HOME/eventscripter/system/overwriteFile.js
/*jslint browser */
/*global getPath, writeFile */
function overwriteFile(path, content) {
    "use strict";

    try {
        var file = getPath(path);
        if (file.exists()) {
            file.delete();
        }
        writeFile(path, content, false);
        return true;
    } catch (ignore) {
        return false;
    }
}