I have a webpage where I am fetching the name of files in a Folder into an array using VBScript, then I am passing that array to JavaScript variable, so that I can display the names on the screen.
VBScript Code:
Function allFiles()
Dim arr, arr2, oTargetFolder
arr = array()
set oFSO = CreateObject("Scripting.FileSystemObject")
oTargetFolder = "C:\Users\msiddiq1\Documents\WSDLs"
set objFolder = oFSO.GetFolder(oTargetFolder)
set oFiles = objFolder.Files
For Each files in oFiles
ReDim Preserve arr(UBound(arr) + 1)
arr(UBound(arr)) = files.Name
Next
allFiles = arr
End Function
JS:
var folderFiles = allFiles();
alert(folderFiles.length); // alerts `undefined`
I can pass hardcoded values from vbscript to javascript, but not this array.
Please suggest.
asked May 11, 2015 at 9:53
Ejaz
1,6425 gold badges28 silver badges54 bronze badges
-
Just return a comma separated string instead of array. Split it inside JavaScript.Salman Arshad– Salman Arshad2015年05月11日 10:15:40 +00:00Commented May 11, 2015 at 10:15
1 Answer 1
You have to wrap the resulting array in a VBArray object and call toArray:
var folderFiles = new VBArray(allFiles());
var ff = folderFiles.toArray();
alert(ff.length);
or in one line:
var folderFiles = (new VBArray(allFiles())).toArray();
Note that VBScript is deprecated in IE11 edge mode, so it will be disappearing at some point.
user692942
16.4k8 gold badges85 silver badges196 bronze badges
answered May 11, 2015 at 10:10
James Thorpe
32.3k6 gold badges76 silver badges95 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default