• Writing to a text file

    From Lab Rat@VERT/TOXIC to All on Thu Feb 6 23:55:22 2014
    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!ããThanks,ããLab Rat.ããã---ã þ Synchronet þ Toxic Laboratory BBS - Birmingham, UK - toxicbbs.comã
  • From Digital Man@VERT to Lab Rat on Thu Feb 6 17:46:13 2014
    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 þ [vert/cvs/bbs].synchro.netã
  • From MCMLXXIX@VERT/MDJ to Lab Rat on Thu Feb 6 21:09:09 2014
    Re: Writing to a text fileã By: Lab Rat to All on Thu Feb 06 2014 23:55:22ãã > var f = new File('test.txt');ã > file.open('w');ã > file.writeln('Line 1');ã > file.writeln('Line 2');ã > file.close();ããthis actually looks fine to me... you can try checking whether or not theãfile.open() was successful ala var didItOpen = file.open('w');ãã---ã þ Synchronet þ The BRoKEN BuBBLE (bbs.thebrokenbubble.com)ã
  • From Lab Rat@VERT/TOXIC to Digital Man on Fri Feb 7 11:02:41 2014
    Re: Writing to a text fileã By: Digital Man to Lab Rat on Thu Feb 06 2014 17:46:13ãã > "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!ãã > 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.ããI tried looking through a good few but being all wrapped up in functions withãarrays, I just got even more confused - but makes sense now.ããThanks DM, all working fine now. Most appreciated.ããLab Rat.ããã---ã þ Synchronet þ Toxic Laboratory BBS - Birmingham, UK - toxicbbs.comã
  • From Lab Rat@VERT/TOXIC to MCMLXXIX on Fri Feb 7 11:05:58 2014
    Re: Writing to a text fileã By: MCMLXXIX to Lab Rat on Thu Feb 06 2014 21:09:09ãã > 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!ããLab Rat.ããã---ã þ Synchronet þ Toxic Laboratory BBS - Birmingham, UK - toxicbbs.comã
  • From MCMLXXIX@VERT/MDJ to Lab Rat on Fri Feb 7 11:29:48 2014
    Re: Writing to a text fileã By: Lab Rat to MCMLXXIX on Fri Feb 07 2014 11:05:58ãã > 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!ããwell, it's good that he was paying attention.. clearly i wasn't :Dãã---ã þ Synchronet þ The BRoKEN BuBBLE (bbs.thebrokenbubble.com)ã
  • From Nightfox@VERT/DIGDIST to Lab Rat on Fri Feb 7 11:18:30 2014
    "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!ããThat code is JavaScript, not Java.ããNightfoxãã---ã þ Synchronet þ Digital Distortion BBS - digitaldistortionbbs.comã
  • From Deuce@VERT/SYNCNIX to Lab Rat on Fri Feb 7 11:39:30 2014
    Re: Writing to a text fileã By: Lab Rat to All on Thu Feb 06 2014 11:55 pmãã > 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.ãã---ãhttp://DuckDuckGo.com/ a better search engine that respects your privacy.ã þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)ã
  • From Lab Rat@VERT/TOXIC to Deuce on Sat Feb 8 13:13:00 2014
    Re: Writing to a text fileã By: Deuce to Lab Rat on Fri Feb 07 2014 11:39:30ãã > Since you're not specifying a path, I think it goes in the ctrl directory.ããI was looking all over for it (including ctrl directory) and it wasn't working.ãAll working fine now with the f... (or whatever I declare) as opposed toãfile...ããLab Ratããã---ã þ Synchronet þ Toxic Laboratory BBS - Birmingham, UK - toxicbbs.comã