Efty

OutlookEX UDF - Double Entries on Export

10 posts in this topic

#1 ·  Posted (edited)

Hi, 

i use the latest AutoIt Version combined with the latest Outlook UDF. My following script should export the whole Outlook 2007 content to a new pst-file and works flawless. Except on thing...

Every subfolder which resists in a main folder will also be visible in the root of the new pst-file. Here is an quick example...

Original PST                New PST

\contacts                   \contacts
\contacts\business          \business
\contacts\private           \private
                            \contacts\business
                            \contacts\private

 

... and here's my script.

; Pfad zum OutlookEx UDF
#include <udf\OutlookEx.au3>
#include <array.au3>

; SplashText Hinweis für die Dauer des Scripts
SplashTextOn("Bitte warten...", "Aktives Postfach wird exportiert...", @DesktopWidth - 40, 45, 20, @DesktopHeight - 100, 5, "")

; Verbindung zu Outlook öffnen
Global $oOutlook = _OL_Open()

; Pfad zur PST-Datei
$oPSTPfad = @ScriptDir & "\"

; Name der PST-Datei
$oPSTName = "[" & @YEAR & "-" & @MON & "-" & @MDAY & "] " & StringUpper(@UserName)

; Evtl. vorhandene PST-Datei löschen
If FileExists($oPSTPfad & $oPSTName & ".pst") = TRUE Then FileDelete($oPSTPfad & $oPSTName & ".pst")
    
; PST-Datei im Unicode-Format erstellen und öffnen
$oPST = _OL_PSTCreate($oOutlook, $oPSTPfad & $oPSTName & ".pst", $oPSTName, $olStoreUnicode)

; Alle Ordner des aktiven Postfachs ermitteln
$aFolders = _OL_FolderTree($oOutlook, "*")

; Länge der Postfachbezeichnung ermitteln
Global $iRoot = StringLen($aFolders[0])
Global $count = UBound($aFolders) - 1

; Alle Ordner des Postfachs durchlaufen
For $i = 1 To UBound($aFolders) - 1

    ; Ordner Pfad in der Postfachstruktur ermitteln und 'Erinnerungen' berücksichtigen
    if $aFolders[$i] <> "Erinnerungen" Then
        $aFolder = StringRight($aFolders[$i], StringLen($aFolders[$i]) - $iRoot)
    Else
        $aFolder = "Erinnerungen"
    Endif

    ; Hinweis aktualisieren
    ControlSetText("Bitte warten...", "", "Static1", "[" & $i & "|" & $count & "] " & StringUpper($aFolder) & " wird exportiert...")
    
    ; Inhalt des Ordners in die PST-Datei schreiben
    _OL_FolderCopy($oOutlook, "*\" & $aFolder, $oPST & "\" & $aFolder)
    
Next

; PST-Datei schliessen
_OL_PSTClose($oOutlook, $oPST)

; Outlook schliessen
_OL_Close($oOutlook)

 

Can anyone please give me an advice!?

Thanx in advance.

Kind regards

Efty

Edited by Efty

Share this post


Link to post
Share on other sites



Could you please set the level for _OL_FolderTree (parameter $iLevel = 1) to 1 and try again?
Now _OL_Foltertree returns all levels of folders and _OL_FolderCopy copies the specified folder plus all subfolders. So you are doing it twice at the moment.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi water,

first i would to thank you for your quick reply and the fantastic udf. It saved me a lot of time.

So - i've done as told. I modified my code, set the folder Level to 1 and removed the Loop through the Folder Array.

The script runs without error but the newly created pst-file is empty, but has a size of 271 kbyte.

; Include-Dateien
#include <udf\OutlookEx.au3>
#include <array.au3>

; Verbindung zu Outlook öffnen
$oOutlook = _OL_Open()

; Pfad zur PST-Datei
$oPSTPfad = @ScriptDir & "\"

; Name der PST-Datei
$oPSTName = "[" & @YEAR & "-" & @MON & "-" & @MDAY & "]  " & StringUpper(@UserName)

; PST-Datei im Unicode-Format erstellen und öffnen
$oPST = _OL_PSTCreate($oOutlook, $oPSTPfad & $oPSTName & ".pst", $oPSTName, $olStoreUnicode)

; Alle Ordner des aktiven Postfachs ermitteln
$aFolders = _OL_FolderTree($oOutlook, "*", 1)

; Inhalt des Ordners in die PST-Datei schreiben
_OL_FolderCopy($oOutlook, $aFolders[0], $oPST)

; PST-Datei schliessen
_OL_PSTClose($oOutlook, $oPST)

; Outlook schliessen
_OL_Close($oOutlook)

I also replaced the $aFolders[0] in _OL_FolderCopy with "*", "\\Postfach - Edge, Efty", etc. but nothing worked.

Can you please help me once again to export the whole Outlook content to a pst-file!?

Kind regards

Efty

Edited by Efty

Share this post


Link to post
Share on other sites

You need to add some error checking. Do you get the expected results (Array, @error always 0)?

; Include-Dateien
#include <udf\OutlookEx.au3>
#include <array.au3>

; Verbindung zu Outlook öffnen
$oOutlook = _OL_Open()
MsgBox(0, "", "Open: @error = " & @error & ", @extended = " & @extended)

; Pfad zur PST-Datei
$oPSTPfad = @ScriptDir & "\"

; Name der PST-Datei
$oPSTName = "[" & @YEAR & "-" & @MON & "-" & @MDAY & "]  " & StringUpper(@UserName)

; PST-Datei im Unicode-Format erstellen und öffnen
$oPST = _OL_PSTCreate($oOutlook, $oPSTPfad & $oPSTName & ".pst", $oPSTName, $olStoreUnicode)
MsgBox(0, "", "PST create: @error = " & @error & ", @extended = " & @extended)

; Alle Ordner des aktiven Postfachs ermitteln
$aFolders = _OL_FolderTree($oOutlook, "*", 1)
MsgBox(0, "", "Foldertree: @error = " & @error & ", @extended = " & @extended)
_ArrayDisplay($aFolders)

; Inhalt des Ordners in die PST-Datei schreiben
_OL_FolderCopy($oOutlook, $aFolders[0], $oPST)
MsgBox(0, "", "Foldercopy: @error = " & @error & ", @extended = " & @extended)

; PST-Datei schliessen
_OL_PSTClose($oOutlook, $oPST)
MsgBox(0, "", "PST close: @error = " & @error & ", @extended = " & @extended)

; Outlook schliessen
_OL_Close($oOutlook)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I redirected the Errors to the console, here is what it Looks like

Open:       @error = 0, @extended = 0
PST create: @error = 0, @extended = 0
Foldertree: @error = 0, @extended = 0
Foldercopy: @error = 1, @extended = 1
PST close:  @error = 0, @extended = 0
[Finished in 2.2s]

and the ArrayDisplay shows following

Row     Col 0
[0]     \\Postfach - Edge, Efty

I hope it helps.

Efty

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

How many entries do you have in the displayed array? Only one?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Right, only One. If i remove the $iLevel Parameter i See the root folder structure under \\Postfach - Edge, Efty. But then i have double entries 

Share this post


Link to post
Share on other sites

Fine. Then I suggest to use

$aFolders = _OL_FolderTree($oOutlook, "*", 2)

and ignore the root directory

\\Postfach - Edge, Efty

To copy the remaining folders you need to remove the leading "\\".


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hi water,

thank you very, very much. Now it works like charm. 

Here for all there are interested in the solution the complete code.

Pfad zum OutlookEx UDF
#include <udf\OutlookEx.au3>
#include <array.au3>

; SplashText Hinweis für die Dauer des Scripts
SplashTextOn("Bitte warten...", "Aktives Postfach wird exportiert...", @DesktopWidth - 40, 45, 20, @DesktopHeight - 100, 5, "")

; Verbindung zu Outlook öffnen
Global $oOutlook = _OL_Open()

; Pfad zur PST-Datei
$oPSTPfad = @ScriptDir & "\"

; Name der PST-Datei
$oPSTName = "[" & @YEAR & "-" & @MON & "-" & @MDAY & "] " & StringUpper(@UserName)

; Evtl. vorhandene PST-Datei löschen
If FileExists($oPSTPfad & $oPSTName & ".pst") = TRUE Then FileDelete($oPSTPfad & $oPSTName & ".pst")
    
; PST-Datei im Unicode-Format erstellen und öffnen
$oPST = _OL_PSTCreate($oOutlook, $oPSTPfad & $oPSTName & ".pst", $oPSTName, $olStoreUnicode)

; Alle Ordner des aktiven Postfachs ermitteln
$aFolders = _OL_FolderTree($oOutlook, "*", 2)

; Länge der Postfachbezeichnung ermitteln
Global $iRoot = StringLen($aFolders[0])
Global $count = UBound($aFolders) - 1

; Alle Ordner des Postfachs durchlaufen
For $i = 1 To UBound($aFolders) - 1

    ; Ordner Pfad in der Postfachstruktur ermitteln und 'Erinnerungen' berücksichtigen
    if $aFolders[$i] <> "Erinnerungen" Then
        $aFolder = StringRight($aFolders[$i], StringLen($aFolders[$i]) - $iRoot)
    Else
        $aFolder = "Erinnerungen"
    Endif

    ; Hinweis aktualisieren
    ControlSetText("Bitte warten...", "", "Static1", "[" & $i & "|" & $count & "] " & StringUpper($aFolder) & " wird exportiert...")
    
    ; Inhalt des Ordners in die PST-Datei schreiben
    _OL_FolderCopy($oOutlook, "*\" & $aFolder, $oPST & "\" & $aFolder)
    
Next

; PST-Datei schliessen
_OL_PSTClose($oOutlook, $oPST)

; Outlook schliessen
_OL_Close($oOutlook)

 

Kind regards and thumbs up to the very good support!

Efty

Edited by Efty

Share this post


Link to post
Share on other sites

Glad to be of service :)
Schöne Grüße


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now