ActiveXObject(“Scripting.FileSystemObject”) not working for me

混江龙づ霸主 提交于 2019-12-13 04:38:15

问题


I want to add names of files of a specific folder to an JS's array, but nothing happens:

var pics = new Array();

var x;
var fs = new ActiveXObject("Scripting.FileSystemObject");
alert('x');
var fo = fs.GetFolder(Server.MapPath("C:\wamp\www\newsite\ErfanGhiasiPanel\Slider Images"));
for (x in fo.files){
    pics.push(x.Name);
}

For instance, whet I insert an

alert('something')

after var fs = new ActiveXObject... or next lines, it won't appear. What you guys think?

Thank you


回答1:


Assuming JScript + Classic ASP due to the MapPath (which you dont need in your case) you need to escape the path string;

var pics = [];
var fs = new ActiveXObject("Scripting.FileSystemObject");
var fo = new Enumerator(fs.GetFolder("C:\\wamp\\www\\newsite\\ErfanGhiasiPanel\\Slider Images").Files);

for (; !fo.atEnd(); fo.moveNext()) {
    pics.push(fo.item(0).Name)
}


来源:https://stackoverflow.com/questions/8823136/activexobjectscripting-filesystemobject-not-working-for-me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!