Hi all,
Unfortunately, Javascript isn't my first (programming) language and I'm struggling to get to grips with creating a simple plain text file from a script. I've spent hours staring at the JS Object Model Reference (http://synchro.net/docs/jsobjs.html) and I just cannot work it out.
This is what I've got so far:
var f = new File('test.txt');
file.open('w');
file.writeln('Line 1');
file.writeln('Line 2');
file.close();
I've tried the file.open(file_exists(file.name) ? 'r+':'w+'); line
mentioned in the documentation and I just cannot get this to work.
Any code suggestions would be welcome!
var f = new File('test.txt');
file.open('w');
file.writeln('Line 1');
file.writeln('Line 2');
file.close();
"file" is not defined in that example. I think you meant to write f.open(), f.writeln(), and f.close().
There are many examples in the exec/*.js files which open/modify files. You could look at those for some tips or inspiration as well.
this actually looks fine to me... you can try checking whether or not the file.open() was successful ala var didItOpen = file.open('w');
As DM said, I needed to use the variable that I had declared as a file, not just the word 'file'. All working now though, thanks for the reply!
"file" is not defined in that example. I think you meant to write f.open(), f.writeln(), and f.close().
Ah, that makes a lot of sense! See, Java isn't my best programming
language!
var f = new File('test.txt');
file.open('w');
file.writeln('Line 1');
file.writeln('Line 2');
file.close();
I've tried the file.open(file_exists(file.name) ? 'r+':'w+'); line
mentioned in the documentation and I just cannot get this to work.
Since you're not specifying a path, I think it goes in the ctrl directory.
Sysop: | digital man |
---|---|
Location: | Riverside County, California |
Users: | 1,043 |
Nodes: | 15 (0 / 15) |
Uptime: | 42:08:58 |
Calls: | 500,900 |
Calls today: | 3 |
Files: | 109,370 |
D/L today: |
4,753 files (492M bytes) |
Messages: | 304,224 |