[Jslib] Opening files in Windows

Pete Collins pete at mozdevgroup.com
Mon Aug 2 10:55:02 EDT 2004


> What is the path I pass to File constructor?  I tried
>
> var f = new File('file:///C|/foo/bar.txt');

var f = new File("c:\\foo\\bar.txt");

Note the double slashes. This is a javascript issue since js will think 
you are trying to escape the "f" and "b" in "c:\foo\bar.txt" string.

For *easily* getting various directories on the system, just use jsLib 
dirUtils:

  http://jslib.mozdev.org/libraries/io/dirUtils.js.html

So for example, you could do something like this:

include (jslib_io);

var f = new File(getMozUserHomeDir());
f.append("bar.txt");

On windows XP this would translate to somthing like:

c:\Documents and Settings\winXPUser\Application Data\ 
Mozilla\Profiles\default\...slt"

--pete

-- 
Pete Collins - Founder, Mozdev Group Inc.
www.mozdevgroup.com
Mozilla Software Development Solutions 




More information about the Jslib mailing list