Winscripter
  WSH
  Forums
  Downloads
  Books
  Links
  Amazon




Login
Register

© winscripter.com
1998-2004







Script: List Files in a Folder

Posted by on Sunday, January 18, 2004 (PST)

Script: Using the FileSystemObject, displays all the files in a folder.

 


/**
 *    Script:     FileList.js
 *    Purpose:    Used to retrieve and display all the files in a folder.
 *                Does not show child folders or their contents.
 *    Author:     Daren Thiel
 *    Date:       21 November 1998
 *    Note:       Rename this file FileList.js
 *    Web:       
http://www.winscripter.com
 **/
/* Create the FileSystemObject */
fso = new ActiveXObject("Scripting.FileSystemObject");
/* Point the Object to a specific folder */
fsofolder = fso.GetFolder("C:\\temp");
/* get a collection of the files contained in that folder */
colFiles  = fsofolder.Files;
/* Create an Enumerator so that we can move through the collection */
fc = new Enumerator( colFiles );
/* Create a variable to store an output message in */
var msg = "";
/* Loop through the Enumerator and add each item to our variable */
for (; !fc.atEnd(); fc.moveNext() ){
 msg += fc.item() + "\n";
}
/* Show the user the results */
WScript.Echo( msg );
 



WSH and ADSI Administrative Scripting


Winscripter   |  WSH   |  Forums   |  Downloads   |  Books   |  Links   |  Amazon