To implement File/Folder select for firefox extensions you can look at the nsIFilePicker component.
To get the object:
var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(Components.interfaces.nsIFilePicker);
The object at this point is not initialized yet, you will need to use the init method to initialized it.
The method looks like this void init(parent,title,mode).
For parent you can use the window object that should be present. title is just the title of the file dialog, mode consist of any of the following valid values.
| Constant |
Value |
Description |
modeOpen |
0 |
Load a file or directory. |
modeSave |
1 |
Save a file or directory. |
modeGetFolder |
2 |
Select a folder/directory. |
modeOpenMultiple |
3 |
Load multiple files. |
Next you will need to call the show() method and check its return value to see if what the user pressed.
A sample of how to use;
const nsiFilePicker=Components.interfaces.nsIFilePicker;
fp.init(window,"My File dialog",nsIFilePicker.modeGetFolder);
var result=fp.show();
if(result == nsIFilePicker.returnOK || result == nsIFilePicker.returnReplace){
//do something
}