Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Find Duplicate folders only from 4 of my Pst's. Need to scan each and every folder name in all pst's in the outlook and get the duplicate folder names alone to an excel/txt file.

Hi,

Find Duplicate folders only from 4 of my Pst's. Need to scan each and every folder name in all pst's in the outlook and get the duplicate folder names alone to an excel/txt file.
Scan all sub folders and folders and get the duplicates. Can be 2 or more too. Need the full path shown.

REgards
Sharath
Avatar of Dave
Dave
Flag of Australia image

Sharath,
Change these lines to your  PST file names
  • MyPsts(1) = "2003"
  • MyPsts(2) = "2004"
  • MyPsts(3) = "2005"
  • MyPsts(4) = "2006"
The code will dump any dupes (against the original name) to c:\duplist.csv
Cheers
Dave

ption Explicit
 
Sub FolderList()
    Dim myNamespace As Outlook.NameSpace
    Dim MyPsts(1 To 4) As String, Pst
    Dim MyDic, objFSO, objTextFile
    Dim MainFolder As MAPIFolder
 
    Set objFSO = CreateObject("scripting.filesystemobject")
    Set objTextFile = objFSO.createtextfile("c:\duplist.csv")
    Set myNamespace = Application.GetNamespace("MAPI")
    Set MyDic = CreateObject("scripting.dictionary")
    MyPsts(1) = "2003"
    MyPsts(2) = "2004"
MyPsts(3) = "2005"
MyPsts(4) = "2006"
    For Each Pst In MyPsts
        Set MainFolder = myNamespace.Folders(Pst)
        Call ProcessFolder(MainFolder, MyDic, objTextFile)
    Next
    Set MyDic = Nothing
    objTextFile.Close
    Set objFSO = Nothing
    
    MsgBox "Done"
End Sub
 
 
 
Sub ProcessFolder(ByVal MainFolder As MAPIFolder, ByVal MyDic, ByVal objTextFile)
    Dim objFolder As Outlook.MAPIFolder
 
    For Each objFolder In MainFolder.Folders
        If MyDic.exists(objFolder.Name) Then
            objTextFile.Write objFolder.FolderPath & "," & Right$(MyDic(objFolder.Name), Len(MyDic(objFolder.Name)) - InStr(MyDic(objFolder.Name), "|||") - 2)
            objTextFile.Writeline
        Else
            MyDic.Add objFolder.Name, objFolder.Name & "|||" & objFolder.FolderPath
        End If
        Call ProcessFolder(objFolder, MyDic, objTextFile)
    Next
    Set objFolder = Nothing
End Sub

Open in new window

Avatar of bsharath

ASKER

Thanks Dave i get this

the operation failed. An object could not be found...

        Set MainFolder = myNamespace.Folders(Pst)
I have changed the code with 4 pst file names
Sharath,
The codde below will run over all all of your folders - lets see if this works for you before we refine it to your 4 specific psts
Cheers
Dave

Option Explicit
Sub FolderList()
    Dim myNameSpace As Outlook.NameSpace
    Dim Pst
    Dim MyDic, objFSO, objTextFile
    Dim MainFolder As MAPIFolder
 
    Set objFSO = CreateObject("scripting.filesystemobject")
    Set objTextFile = objFSO.createtextfile("c:\duplist.csv")
    Set myNameSpace = Application.GetNamespace("MAPI")
    Set MyDic = CreateObject("scripting.dictionary")
 
    For Each Pst In myNameSpace.Folders
        Set MainFolder = myNameSpace.Folders(Pst.Name)
        Call ProcessFolder(MainFolder, MyDic, objTextFile)
    Next
    Set MyDic = Nothing
    objTextFile.Close
    Set objFSO = Nothing
 
    MsgBox "Done"
End Sub
 
 
 
Sub ProcessFolder(ByVal MainFolder As MAPIFolder, ByVal MyDic, ByVal objTextFile)
    Dim objFolder As Outlook.MAPIFolder
 
    For Each objFolder In MainFolder.Folders
        If MyDic.exists(objFolder.Name) Then
            objTextFile.Write objFolder.FolderPath & "," & Right$(MyDic(objFolder.Name), Len(MyDic(objFolder.Name)) - InStr(MyDic(objFolder.Name), "|||") - 2)
            objTextFile.Writeline
        Else
            MyDic.Add objFolder.Name, objFolder.Name & "|||" & objFolder.FolderPath
        End If
        Call ProcessFolder(objFolder, MyDic, objTextFile)
    Next
    Set objFolder = Nothing
End Sub

Open in new window

Dave can we exclude the Public folders please... As it has already taken an hr to read the public folders alone...
Dave can we exclude the Public folders please... As it has already taken an hr to read the public folders alone...
ASKER CERTIFIED SOLUTION
Avatar of Dave
Dave
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks...
Results would be if duplicate it will be seen in Colum C & D and so on?
Thanks...
Results would be if duplicate it will be seen in Colum C & D and so on?
Column A will contain the orginal location
Column B the duplicate path
If there were say three repeat foldernames you would get
A                          B
orig path          dup path1
x xxxx                   yyyy
orig path          dup path2
Cheers
Dave
 
 
Thanks a lot Dave...
Any help on the other post...
Thanks a lot Dave...
Any help on the other post...