• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 549
  • Last Modified:

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

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

1 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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now