Access Directory structure from Javascript

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

Access Directory structure from Javascript

Post by Birdy27 »

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
User avatar
andyed
Posts: 78
Joined: November 5th, 2002, 6:31 am
Location: Clemson, SC
Contact:

JSLib does the Filesystem

Post by andyed »

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

XPCOM

Post by Birdy27 »

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)
Contact:

LocalFile

Post by Torisugari »

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

Permission denied

Post by Birdy27 »

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 by doron »

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

of course

Post by Birdy27 »

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
User avatar
bzbarsky
Posts: 478
Joined: November 5th, 2002, 1:36 pm

Where you can use XPCOM from

Post by bzbarsky »

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 by doron »

Post Reply