Wednesday, April 21, 2010

VBScript tips - Recursive file search

'Create the FileSystemObject
Set objFSO = Createobject("Scripting.FileSystemObject")

'Specify the folder that will be the root
strFolder = "C:\dell" 'using dell directory is just example

'This script is designed to run from the command line and will write out all files
'Here we call the subroutine
GetFiles strFolder

'Here is the sub
Sub GetFiles(ByVal strDirectory)
Set objFolder = objFSO.GetFolder(strDirectory)
'This gets the files from the root directory
For Each objFile in objFolder.Files
Wscript.Echo objFile.Path
Next
'This is the recursion - it gets all subfolders and files within
For Each objFolder in objFolder.SubFolders
GetFiles objFolder.Path
Next
End Sub

No comments:

New beginner's guide to PowerShell on my GitHub page

 I created a beginner's guide to PowerShell here: https://github.com/aamjohns/Powershell_Guide/blob/main/README.md I hope it helps someo...