• Reading files in the current dir

    From Nightfox@VERT/DIGDIST to All on Thu Jun 11 16:17:04 2009
    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 Thu Jun 11 19:27:50 2009
    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 Thu Jun 11 20:44:32 2009
    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ã