I’m forced to use JavaScript for an implementation, and for such implementation I need to list the files of a directory.
At first, it seems easy since we can get the following code from the Microsoft documentation:
var FSO = Server.CreateObject("Scripting.FileSystemObject");
// Reference the Text directory
var Folder = FSO.GetFolder("c:\Text");
// Reference the File collection of the Text directory
var FileCollection = Folder.Files;
Response.Write("JScript Method<BR>");
// Display the number of files within the Text directory
Response.Write("Number of files found: " + FileCollection.Count + "<BR>");
// Traverse through the FileCollection using the FOR loop
for(var objEnum = new Enumerator(FileCollection); !objEnum.atEnd(); objEnum.moveNext()) {
strFileName = objEnum.item();
Response.Write(strFileName + "<BR>");
}
// Destroy and de-reference enumerator object
delete objEnum;
objEnum = null;
// De-reference FileCollection and Folder object
FileCollection = null;
Folder = null;
// Destroy and de-reference FileSystemObject
delete FSO;
FSO = null;
Code source: Microsoft documentation
But actually the JavaScript that I’m using do not has the Enumerator
class. Is there any way to iterate such object without it?
Thank you,