Introduction
This article is offered to you as a short simple poem written in Ruby. It is by no means a masterpiece, but utility in the smallest of circumstances could cause a shift of balance in popular, everyday life.
The Purpose
Imagine you work with the Outlook program running on Windows. You might have a lot of folders in your personal store because you respect yourself as an organized and thorough professional? Perhaps you are so desperate sometimes to find these folders that you are even willing to open a command line "DOS" console if someone suggested it might help?
The Script
Running the following little Ruby program from the command line and passing at least a part of the folder name you would like to locate as an argument, should find the first folder with such a name. If so, it will ask Outlook to jump to the folder and display itself.
</a>
</a>
require 'win32ole'
@outlook_server = "Outlook.Application"
module Outlook
OlFolderCalendar = 9
OlFolderContacts = 10
OlFolderDeletedItems = 3
OlFolderDrafts = 16
OlFolderInbox = 6
OlFolderJournal = 11
OlFolderNotes = 12
OlFolderOutbox = 4
OlFolderSentMail = 5
OlFolderTasks = 13
VbBinaryCompare = 0
VbTextCompare = 1
end
def getoutlook
begin
WIN32OLE.connect(@outlook_server)
rescue
WIN32OLE.new(@outlook_server)
end
end
def getmapinamespace
getoutlook.GetNameSpace('mapi')
end
def getparentfolder_of_personalfolders
getmapinamespace.folders('Personal Folders')
end
def getparentfolder_of_inbox
getmapinamespace.GetDefaultFolder(<a href="outlook::OlFolderInbox%29.Parentend">Outlook::OlFolderInbox).Parent
end
</a>
def dumptree(oparentfolder)
ofolders=oparentfolder.Folders
ifolders=ofolders.count
ofolder=ofolders.getFirst
1.upto(ifolders) do |i|
puts '-- ' + i.to_s + ': ' + ofolder.Name
if 0 < ofolder.folders.count then dumptree(ofolder) end
ofolder=ofolders.getNext
end
end
def searchtree(oparentfolder, sfind)
sfolder=''
tfolder=nil
ffolder=nil
sfind=sfind.downcase
ofolders=oparentfolder.Folders
ifolders=ofolders.count
ofolder=ofolders.getFirst
1.upto(ifolders) do |i|
sfolder=ofolder.Name.downcase
if not sfolder.index(sfind)
if 0 < ofolder.folders.count
tfolder=searchtree(ofolder,sfind)
if tfolder
ffolder=tfolder
return ffolder
end
end
else
ffolder=ofolder
return ffolder
end
ofolder=ofolders.getNext
end
return ffolder
end
def choosestartfolder()
begin
getparentfolder_of_personalfolders()
rescue
getparentfolder_of_inbox()
else
nil
end
end
folder_to_find = ARGV[0]
otl = getoutlook
puts '-- find folder : ' + folder_to_find
puts '-- outlook version : ' + otl.version
puts '-- start folder : ' + choosestartfolder.name
if tfolder = searchtree( choosestartfolder(), folder_to_find )
puts '-- found [' + folder_to_find + '] in [' + tfolder.Name + ']'
otl.ActiveExplorer.CurrentFolder = tfolder;
else
printf '-- folder "%s" not found', folder_to_find
end
The Result
Should be a hop to the first folder with the string "_of_ruby" in its name.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.