Subj : Writing to a text file
To : Lab Rat
From : Digital Man
Date : Thu Feb 06 2014 05:46 pm
Re: Writing to a text file
By: Lab Rat to All on Thu Feb 06 2014 11:55 pm
> 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();
"file" is not defined in that example. I think you meant to write f.open(),
f.writeln(), and f.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.
Replacing "file" with "f" in your example seems to work fine for me (creates a
file "test.txt" with the 2 lines you have specified).
> Any code suggestions would be welcome!
Your code looks fine (except for the file/f confusion I mentioned). It might be
confusing to you that the file being created/written will be located in your
Synchronet "ctrl" directory since you did not specify a full pathname for the
file.
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.
digital man
Synchronet "Real Fact" #3:
Synchronet version 3 is written mostly in C, with some C++, x86 ASM, and Pascal.
Norco, CA WX: 50.6�F, 92.0% humidity, 2 mph W wind, 0.12 inches rain/24hrs
---
� Synchronet � Vertrauen � Home of Synchronet � telnet://vert.synchro.net