I'm using the recursive function posted here:
https://www.autohotkey.com/boards/viewtopic.php?t=61520#p260796
It loops through all the subfolders in Outlook based on an email address and a starting (root) folder. I adapted it (and the code that calls it) as follows:
• Uses ComObjCreate instead of ComObjActive (so that Outlook does not have to be active when running the script).
• Runs on Inbox (instead of Test).
• Writes results to a temp output file (instead of a MsgBox).
• Checks for object creation errors.
• Quits Outlook and releases objects.
• Minor cosmetic/coding-style changes.
Here's the modified code:
Code: Select all
#NoEnv
#SingleInstance Force
SetBatchLines,-1
OutputFile:=A_Temp . "\OutlookTest.txt"
FileDelete,%OutputFile%
; https://www.autohotkey.com/boards/viewtopic.php?t=61520#p260796
olApp:=ComObjCreate("Outlook.Application")
If (!IsObject(olApp))
{
MsgBox,4112,Fatal Error,Could not create Outlook object
ExitApp
}
olTestFolder:=olApp.Session.Folders("[email protected]").Folders.Item("Inbox")
If (!IsObject(olTestFolder))
{
MsgBox,4112,Fatal Error,Could not create Folder object
ExitApp
}
Output:=olLoopFolder(olTestFolder)
FileAppend,%Output%,%OutputFile%
olApp.Quit
ObjRelease(olTestFolder)
ObjRelease(olApp)
Run,%OutputFile%
ExitApp
olLoopFolder(olFolder)
{
global OutputFile
FolderEmails:="Folder: " . olFolder.Name . "`n"
For olItem in olFolder.Items
FolderEmails:=FolderEmails . A_Index . ">" . olItem.Subject . "`n"
For olSubFolder in olFolder.Folders
FolderEmails:=FolderEmails . "`n" . olLoopFolder(olSubFolder)
Return FolderEmails
}
I'd like a change to this but haven't been able to come up with the solution myself, so am reaching out for help. As it stands now, the folder name captured — in the FolderEmails:="Folder: " . olFolder.Name . "`n" statement of the recursive function — is the folder name only. I'd like it to be the entire path to that folder name. For example, let's say there's the following folder structure in the Inbox:
Inbox
Banks
Bank of America
Check images
Statements
Wells Fargo
Check images
Statements
The function as written now will show these folder names:
Inbox
Banks
Bank of America
Check images
Statements
Wells Fargo
Check images
Statements
I'd like it to show:
Inbox
Inbox-Banks
Inbox-Banks-Bank of America
Inbox-Banks-Bank of America-Check images
Inbox-Banks-Bank of America-Statements
Inbox-Banks-Wells Fargo
Inbox-Banks-Wells Fargo-Check images
Inbox-Banks-Wells Fargo-Statements
In other words, the full path to the folder. Thanks much, Joe