' +----------------------------------------------------------------------------+ ' | Jeffrey M. Hunter | ' | jhunter@idevelopment.info | ' | www.idevelopment.info | ' |----------------------------------------------------------------------------| ' | Copyright (c) 1998-2009 Jeffrey M. Hunter. All rights reserved. | ' |----------------------------------------------------------------------------| ' | FILE : FileList.vbs | ' | CLASS : Files and Directories | ' | PURPOSE : List all files in a Directory. | ' | PARAMETERS : None | ' | USAGE : cscript FileList.vbs //NoLogo | ' | NOTE : As with any code, ensure to test this script in a development | ' | environment before attempting to run it in production. | ' +----------------------------------------------------------------------------+ Option Explicit Function Main Dim objFSO, objFile Dim strFolder, colFiles, strMessage ' Create the FileSystemObject object Set objFSO = WScript.CreateObject("Scripting.FileSystemObject") ' Configure FSO to specific folder Set strFolder = objFSO.GetFolder("C:\\temp") ' Get a collection of the files contained in that folder Set colFiles = strFolder.Files ' Iterate through the Collection object and add each file to ' the temp variable strMessage = "" For Each objFile in colFiles ' strMessage = strMessage & objFile.Name & VbCrLf ' Only File Name strMessage = strMessage & objFile.Path & VbCrLf ' Path and File Name Next ' Print all files in directory WScript.Echo strMessage WScript.Quit(0) End Function Main