I am having a difficult time doing file I/O through XPCOM. I am doing a
purely client-side JavaScript application that will present an interface
that an exam writer will use to prepare questions for an exam, and it
will save this to a file (the client-side output). Then an exam taker
will open the exam by reading it in (the client-side input).
The basic interface starts by listing the current directory of the
browser and all its entries. The user goes up or down the directory
tree either to find the directory where the exam is to be written
(stored) or to find the exam to be taken. I can do with this with
ActiveX and now I want to do it with XPCOM. I am having some problems
though:
1) Suppose I have the code
function fopen(fname, ftyp)
{
// the argument fname = ".", i.e. the current directory
// ...large block of code here removed
netscape.security.PrivilegeManager.enablePrivilege
("UniversalXPConnect");
var fObj = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
fObj.initWithPath(fname);
The last statement produces the error
Error: uncaught exception: [Exception... "Component returned
failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)
[nsILocalFile.initWithPath]" nsresult: "0x80520001
(NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame ::
file:///C:/include/fsystem.js :: File :: line 100" data: no]
This was so because fname is the string ".", and apparently this is not
allowed, which seems odd, because if access is being granted to the file
system at any part of the hierarchy, how is accessing the current directory
a security problem?
Now if I put this code:
try {
fObj.initWithPath(fname);
}
catch (e) {
fObj.initWithPath("c:\\");
}
the code moves on and the file path is set to "c:" as reported by the
debugger.
QUESTION: How do I get the file object to be a directory that is set to
the current directory?
2) Thinking that I have at least one file object which is the directory, I
have tried to read the directory entries on the file object:
dirlist = fObj.directoryEntries;
This statement produces the error
Error: uncaught exception: Permission denied to get property
UnnamedClass.directoryEntries
QUESTION: How do I get a list of directory entries?
Thanks very much.
I am using Mozilla 1.7.3/Venkman 0.9.81.
_______________________________________________
Mozilla-xpcom mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-xpcom