XWidgetSoft Forum https://www.bbs.xwidget.com/ |
|
CONTROL: recursive folder and file list https://www.bbs.xwidget.com/viewtopic.php?f=10&t=6700 |
Page 1 of 1 |
Author: | yereverluvinuncleber [ May 27th, 2017, 3:23 am ] |
Post subject: | CONTROL: recursive folder and file list |
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. |
Author: | yereverluvinuncleber [ June 6th, 2017, 11:40 am ] | ||
Post subject: | Re: CONTROL: recursive folder and file list | ||
I have added a small widget that demonstrates the above issue and how the ActiveX control is used to provide a workaround. Jim, this could have been raised as a bug, as a folder list that reports nothing when there are folders in the directory certainly appears as a bug to me. I have provided a workaround in activeX but Tony could take note of these enhancements/workarounds and factor them into a revised Xwidget 1.9. ![]()
|
Page 1 of 1 | All times are UTC - 8 hours |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |