Winscripter
  WSH
  Forums
  Downloads
  Books
  Links
  Amazon




Login
Register

© winscripter.com
1998-2004







Howto: List all the files in a folder

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

Howto: List all the files in a folder. Uses the Scripting.FileSystemObject.

 

/* 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 );

Comments:

Hard Code vs. Search
By OldManRiver on Wednesday, November 29, 2006 (PST)
You hardcoded the folder path\name in your code.

What if you want to search for all folders or select a specific folder from a drive?

OMR



WSH and ADSI Administrative Scripting


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