문제
여기에 폴더에 저장된 파일의 양을 제공하는 코드가 있습니다.
//get file amount in folder
var fileAmount = new ActiveXObject("Scripting.FileSystemObject");
var folderObj = fileAmount.GetFolder("C:\\cnc\\USER"); //pfad, dann in benuzername/dokumente
// create enumerator type of collection of files in folder
var filesCollection = new Enumerator(folderObj.Files);
var fileObj;
for (filesCollection.moveFirst(); !filesCollection.atEnd(); filesCollection.moveNext()) {
fileObj = filesCollection.item();
projName = fileObj.Name;
alert(projName) ; // at the Moment msg. with all file names...
}
.
및 여기에서 "var 파일"에서 가져 오려고합니다.
var files = [
{'name': projName + ',', 'date': ProjDate + ' '} //date is also there but not in the code
],
insertDiv = function(openerWrapper, file){
// create element
var div = document.createElement('div'),
content = "",
_key;
for(_key in file){
if(file.hasOwnProperty(_key)){
content += " " + file[_key];
}
}
// this is content
div.innerHTML = content;
// CSS class
div.className += " metroFileBoxAuto";
openerWrapper.appendChild(div);
};
.
코드가 완벽하게 작동합니다. 'var 파일'에서 더 많은 요소를 넣으면 필요한 모든 DIV 요소를 가져 오지만 'var 파일'에 수동으로 설정해야합니다.수집 된 모든 파일 이름을 'var 파일'에 자동으로 놓을 수있는 방법은 무엇입니까?어떤 아이디어가 있습니까?
해결책
나는 당신이 이렇게 수집 된 파일 이름으로 배열을 채우기 위해 이것을 시도 할 수 있다고 생각합니다.
//get file amount in folder
var fileAmount = new ActiveXObject("Scripting.FileSystemObject");
var folderObj = fileAmount.GetFolder("C:\\cnc\\USER"); //pfad, dann in benuzername/dokumente
// create enumerator type of collection of files in folder
var filesCollection = new Enumerator(folderObj.Files);
var fileObj, files[], projName;
for (filesCollection.moveFirst(); !filesCollection.atEnd(); filesCollection.moveNext()) {
fileObj = filesCollection.item();
projName = fileObj.Name;
alert(projName) ; // at the Moment msg. with all file names...
files.push({'name': projName + ' ,', 'date': 'some_date' + ' '});
}
. 제휴하지 않습니다 StackOverflow