• Reading files in the current dir

    From Nightfox@VERT/DIGDIST to All on Thursday, June 11, 2009 16:17:04
    I have another JS question - Using load() or the File object, is it possible to read files in the script's current directory without specifying the full path, if the script is not in the SBBS exec directory?

    Normally, I like to keep scripts that I develop in their own directory (not
    in the SBBS exec directory). However, if I use load() or the File class to open a file, specifying the current directory (i.e., file.open("./someFile.txt")), it is unable to load the file, even if it's in the same directory as the JavaScript file.

    Similarly, when using load() to load another .js file in the same directory, specifying "./" in the filename doesn't seem to work unless the scripts are
    in the SBBS exec directory.

    Is there a setting somewhere that can be changed for JavaScript file directories, similar to the path environment variable? Or is there something that can be done in JS to ensure that it looks in the current directory for load() and the File class?

    Eric


    ---
    Synchronet Digital Distortion BBS
  • From Digital Man@VERT to Nightfox on Thursday, June 11, 2009 19:27:50
    Re: Reading files in the current dir
    By: Nightfox to All on Thu Jun 11 2009 04:17 pm

    I have another JS question - Using load() or the File object, is it
    possible to read files in the script's current directory without specifying the full path, if the script is not in the SBBS exec directory?

    Normally, I like to keep scripts that I develop in their own directory (not in the SBBS exec directory). However, if I use load() or the File class to open a file, specifying the current directory (i.e., file.open("./someFile.txt")), it is unable to load the file, even if it's
    in the same directory as the JavaScript file.

    The "current directory" for the process (sbbs.exe, sbbsctrl.exe, etc.) is the Synchronet CTRL directory and this must not be changed (since all threads share the current directory).

    If you wish to use a relative directory, use "../" or system.mods_dir + "yourmods" or something similar.

    Similarly, when using load() to load another .js file in the same
    directory, specifying "./" in the filename doesn't seem to work unless the scripts are in the SBBS exec directory.

    The path should not start with './'.

    Is there a setting somewhere that can be changed for JavaScript file directories, similar to the path environment variable? Or is there something that can be done in JS to ensure that it looks in the current directory for load() and the File class?

    You need to specify the absolute path or a relative path from "..". There is a trick where you can 'detect' the directory the script was loaded from using a JavaScript exception. Here's that trick (invented by Deuce):

    var startup_path='.';
    try { throw barfitty.barf(barf) } catch(e) { startup_path=e.fileName } startup_path=startup_path.replace(/[\/\\][^\/\\]*$/,''); startup_path=backslash(startup_path);


    digital man

    Snapple "Real Fact" #126:
    A pigeon's feathers are heavier than its bones.

    ---
    Synchronet Vertrauen Home of Synchronet [vert/cvs/bbs].synchro.net
  • From Nightfox@VERT/DIGDIST to Digital Man on Thursday, June 11, 2009 20:44:32
    Re: Reading files in the current dir
    By: Digital Man to Nightfox on Thu Jun 11 2009 19:27:50

    You need to specify the absolute path or a relative path from "..". There trick where you can 'detect' the directory the script was loaded from usi JavaScript exception. Here's that trick (invented by Deuce):

    Thanks (and thanks to Deuce) - Deuce's trick will work for what I want to do. :)

    Nightfox


    ---
    Synchronet Digital Distortion BBS