Is there a way to check if a file exists? I know something like [ -f xxxx.json ] && echo true || echo false ] but I dont know if I can execute that server-side, sys.system() doens't really work. :x
Code (text): !!sys.getFileContent(name) or Code (text): sys.appendToFile(name, ''); if (sys.getFileContent(name) === '') { // false sys.deleteFile(name); } else { // true } Note that the second example considers empty files to be non-existent as well. However, it does not trigger script warnings if the file doesn't exist.
Ok, thanks. !!sys.getFileContent() works. But for some explanation.. I have never seen two exclamation marks in a row before a statement/function. What does that exactly do?
First one casts the value to boolean and inverts the value, second one inverts the value again. Basically, it's shortest syntax to cast an exprssion to boolean. But usually it is not required in Javascript, as expressions are casted to boolean anyway when relevant in if-clause or while-clause.