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

Reply to this Comment

Add Your Comment



WSH and ADSI Administrative Scripting

New Articles
  • List installed COM objects and associated ProgIDs
    Script: Lists all COM Objects and their associated ProgIDs (If available). Win32_ClassicCOMClassSetting

  • Script: File Rotator
    Script: Rotate files where the most current file has the lowest number in the archive. When files exceed the retention period, they are deleted. Typically used for log files, backups, etc..

  • Script: Create IIS Website and DNS record
    Script: Dan Casier sent me this script that will create a website and appropriate DNS record. The script is intended for Windows 2000 Server with local DNS and necessary DNS mof installed.


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