MozillaZine

Access Directory structure from Javascript

Discussion of general topics about Seamonkey
Birdy27
 
Posts: 26
Joined: November 5th, 2002, 4:37 am

Post Posted November 5th, 2002, 4:40 am

Hi, this threat started on the old forum:

>I just want to ask wether the following is possible (I want it work locally or as XUL-Extension):
>The Goal is to display the directory tree, including fies with specific extension in a HTML document.
>I wrote a Perl program to create such a document,
>but now I want a document that creates itself using DOM, only problem is that Javascript has no commands like "dir"
> or "ls" or whatever. But I think Mozilla should have made this possible, e.g. for extension at least.

> > It would need to be an extension. You can use nsIFile and the .directoryEntries attribute on that.

Can you please give a short example? I never used XPCom objects and don't know how to create/access them.
E.g. how do I get the first entry of path "L:\"?

Ciao/2 Christoph

andyed

User avatar
 
Posts: 78
Joined: November 5th, 2002, 6:31 am
Location: Clemson, SC

Post Posted November 5th, 2002, 6:32 am

Try http://jslib.mozdev.org.

It provides a javascript API on top of the XPCOM file system code. You should find it easy.

Birdy27
 
Posts: 26
Joined: November 5th, 2002, 4:37 am

Post Posted November 5th, 2002, 8:53 am

thanx for the tip, although the lik doesn't work properly I found jslib and I will try it.

Additionally do I like to learn new things, so I would like if someone could give me a start boost example.

Thanx in advance!

Ciao/2 Christoph
Last edited by Birdy27 on November 5th, 2002, 10:05 am, edited 1 time in total.

Torisugari
 
Posts: 1634
Joined: November 4th, 2002, 8:34 pm
Location: Kyoto, Nippon (GMT +9)

Post Posted November 5th, 2002, 8:54 am

You can get nice examples at Xul Planet com.
The article about nsILocalFile is here. http://www.xulplanet.com/tutorials/xultu/xpcom.html

I'm wating for jslib update.
That's grate if we can create a zip file with the library.
Thank you.

Birdy27
 
Posts: 26
Joined: November 5th, 2002, 4:37 am

Post Posted November 5th, 2002, 10:02 am

thanx I went though the introduction, but failed as I get
"Error: uncaught exception: Permission denied to get property UnnamedClass.classes"
I tried to call "Components.classes["@mozilla.org/file/local;1"].createInstance();" from JavaScript from within a normal local HTML file. Is there anything wrong with that?

Ciao/2 Christoph

doron
 
Posts: 935
Joined: November 4th, 2002, 4:50 pm

Post Posted November 5th, 2002, 11:53 am

You can't access XPCOM from a normal webpage, else the webpage could delete your harddisk :)

Birdy27
 
Posts: 26
Joined: November 5th, 2002, 4:37 am

Post Posted November 5th, 2002, 1:09 pm

it's a local HTML file.

Where else could my Javascript be called.

How can I use the XPCOM Features, in wich kind of files und wich circumstances?

Ciao/2 Christoph

bzbarsky

User avatar
 
Posts: 478
Joined: November 5th, 2002, 1:36 pm

Post Posted November 5th, 2002, 1:39 pm

You can use XPCOM from chrome. Local files are still not trustworthy enough for XPCOM access (as stated, such access would allow doing things like deleting files, reading security-critical information, etc, etc). So your file has to be installed as part of the browser (there are tutorials out there on how to do this....)

doron
 
Posts: 935
Joined: November 4th, 2002, 4:50 pm

Post Posted November 5th, 2002, 5:36 pm


Return to SeaMonkey General


Who is online

Users browsing this forum: No registered users and 1 guest