Search all pst file in f:\ root and exclude folder

Posted on 2008-11-17
Last Modified: 2012-06-27
My script scan or search to f:\ root any file with .pst extension and copy to another folder, but i'd like this script exclude folder F:\Documents and Settings\rgaspar\Local Settings\Application Data\Microsoft\Outlook, can i help me?
Option Explicit
Dim oFSO
Dim strUserName
Dim oShell
Dim oEnv
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Wscript.Shell")
Set oEnv = oShell.Environment("SYSTEM")
strUserName = oShell.ExpandEnvironmentStrings("%username%")
SearchPST (oFSO.GetFolder("F:\"))
ExcludeFolder (oFSO.GetFolder("F:\Documents and Settings\rgaspar\Local Settings\Application Data\Microsoft\Outlook"))
Sub SearchPST(objCurrentFolder)
   Dim strTemp
   Dim strOutput
   Dim objNewFolder
   Dim objFile
   On Error Resume Next
   For Each objFile In objCurrentFolder.Files
    strTemp = Right(objFile.Name, 4)
     If UCase(strTemp) = ".PST" Then
   wscript.echo CStr(objFile.Path)
   'oFSO.CopyFile CStr(objFile.Path), "D:\Dados\" & StrUsername & ".$$$" & "\OldPST\" & Date & " " & CStr(objFile.Name)
  End If
 For Each objNewFolder In objCurrentFolder.subFolders
  SearchPST (objNewFolder)
On Error Goto 0
End Sub

Question by:ricgaspar
    1 Comment
    LVL 67

    Accepted Solution

    Should be able to replace the for loop:
    For Each objNewFolder In objCurrentFolder.subFolders
      If objNewFolder <> "F:\Documents and Settings\rgaspar\Local Settings\Application Data\Microsoft\Outlook" Then SearchPST (objNewFolder)

    Open in new window


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Often times network admins need to run domain logon scripts for seperate subnets, but also for a seperate set of computers within that subnet.  In this circumstance, configuring Active Directory Sites and Services then linking a GPO to site/subnet m…
    This is an addendum to the following article: Acitve Directory based Outlook Signature ( The script is fine, and works in normal client-server domains…
    This video discusses moving either the default database or any database to a new volume.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now