Traverse drive/sub-folders

Hi all,

Does anyone know what I need to change to the below so that it searches H:\ and all its subfolders?

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set olkApp = CreateObject("Outlook.Application")
Set objFolder = objFSO.GetFolder(start_folder)
For Each objFile In objFolder.Files
If LCase(objFSO.GetExtensionName(objFile.Name)) = "pst" Then
WScript.Echo "Found PST:" & objFile.Name
olkApp.Session.AddStore objFile.Path
End If

I've looked into traverse etc. but I'm sure there's something better suited.


What language is this?

This could be useful to you:

its looks like vbs or wscript

1 Like

I'm not good with vbs but why not just use a batch file and a command like this

dir -s H:\ | findstr *.pst

ls H:\ | findstr *.pst

also I'm amusing by looking at your code your looking for all files ending in .pst

You could also install cygwin, and use the unix find command:

1 Like

Yes that's correct, this is because a number of people that will be running this have more that one PST file.

Thanks for this, I'll take a look.

In this instance it probably is fine to do so, but every-time I have been involved in a project that requires CygWIn as a dependency, most recently with my current client, it has resulted in an unbelievable headache when building the project in a continuous integration environment (in this case TeamCity running on Windows Server 2012) or on mac dev machines. Otherwise I would agree, find is a very simple solution to the given problem, and if OP is will to do all this in a linux environment or willing to use the linux subsystem for windows, still a viable and elegent solution.


its probably best to just use windows built in commands for compatibility like the ones I previously posted that way you dont need to install anything

1 Like

So after trawling through multiple search results on Google and Reddit over the last couple of days the answer to my "prayers" was discovered.

I found someone that had a solution using Powershell rather than VB.

If anyone is interested the script is located here.