Das sieht ganz gut aus. Gratuliere!
Danke - fehlt "nur" noch das XUL-Äquivalent, sowie ggf. ein Java-Applet für andere Browser (z.B. Opera)...
statt
if(path === "") { path = "./"; }
könnte man auch den Default-Operator || benutzen
Stimmt, daran hatte ich nicht gedacht - danke!
Natürlich muss sichergestellt sein, dass path immer ein String ist. Das gilt auch für deine Variante.
Naja, ich gehe mal davon aus, dass der jwlg. "Nutzer" die Funktion ordentlich bedienen kann - im Kopf steht ja, dass es sich hierbei um einen String handeln sollte...
Hier der aktualisierte Code:
/**
* retrieves directory contents (for Internet Explorer / ActiveX)
* @param {String} [path] absolute or relative path to the respective directory (using the current working directory by default) -- Note: Windows-style backslashes must be escaped (e.g. "C:\\Windows")
* @param {Boolean} [hideFolders] do not include sub-folders
* @param {Boolean} [hideFiles] do not include files
* @return {Array} list of folders and files (returns false on error)
* @todo return object with files'/folders' name, size and date
* @todo opionally remove full path from results
*/
function dirListIE(path, hideFolders, hideFiles) {
path = path || "./";
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(!fso.FolderExists(path)) {
return false; // DEBUG: return empty array?
} else {
var dir = fso.GetFolder(path);
var list = [];
// get subfolders
if(!hideFolders) {
var folders = new Enumerator(dir.SubFolders);
for(; !folders.atEnd(); folders.moveNext()) {
list.push(folders.item());
}
}
// get files
if(!hideFiles) {
var files = new Enumerator(dir.Files);
for(; !files.atEnd(); files.moveNext()) {
list.push(files.item());
}
}
return list;
}
}