There is a bug in the Xwidget getFileList function when used in non-recursive mode that means it fails to report the subfolders contained within a folder. So, if you have a folder with no files within, but does have four sub-folders within then Xwidget fails to return the folders at all instead reporting an empty folder.
The Yahoo widget engine reports folders and files correctly.
This function mimics the yahoo widget engine filesystem.getDirectoryContents function and it uses a combination of Xwidget and activeX functionality to get a file list with folder information when asked to get a listing in non-recursive mode.
validTypes is a variable list that contains a list of valid file types, it needs to be defined globally, eg.
Code:
var validTypes = ["mpeg","mp4","m4a","mpg","flv","mp3","aac","wav","wma","aif","aiff","au","snd"]; //array
Code:
//=================================
// Function to count the folder contents folder by folder
//=================================
function filesystemGetDirectoryContents(folderspec, recursiveBoolean){
var fso, f, fc, fs, s;
if ( recursiveBoolean == false ) {
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
colFiles = f.SubFolders;
fc = new Enumerator( colFiles );
s = "";
for (; !fc.length; fc.moveNext()) {
if (fc.item() == null) {
break;
}
s += fc.item();
s += "|";
}
// now we have the folders - add to the file list
fs = getFileList(folderspec,validTypes,false);
s = s + fs;
} else {
//the xwidget getfilelist does not return an array but a bar-separated list
s = getFileList(folderspec,validTypes,true);
}
// convert the filelist into an array
s = s.split('|');
return s;
}
//=================================
// end function
//=================================
This code successfully fixes Xwidget's faulty getFileList functionality.
It is used in this sense:
Code:
//get the sub-folder list
paths = filesystemGetDirectoryContents(path, false) ;
Naming the new function FilesystemGetDirectoryContents means that any conversion of an Yahoo widget that uses the filesystem.getDirectoryContents code is much easier. These type of translated functions can be added to any Xwidget and the simple removal of a '.' will make the old yahoo widget code compatible.