# Problem in search folder,

**URL:** <https://www.ruby-forum.com/t/problem-in-search-folder/70442>\
**Category:** Ruby\
**Created:** [September 29, 2006, 7:03am UTC](https://www.ruby-forum.com/t/problem-in-search-folder/70442 "2006-09-29T07:03:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinivas224](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e8c25b/32.png) [@srinivas224](https://www.ruby-forum.com/u/srinivas224)\
**Post date:** [September 29, 2006, 7:03am UTC](https://www.ruby-forum.com/t/problem-in-search-folder/70442/1 "2006-09-29T07:03:40Z")

</div>

HI all,

I am software test engineer working Outlook based project,  
Object by using ruby script is user requested folder should select on  
already opened outlook.

I am able to get this functionality on new outlook launch but I want  
these functionality on existed outlook.

I am posting my script please help me according that.

require ‘win32ole’  
olapp = WIN32OLE::new(“outlook.Application”)  
class OutlookConst  
end # load Outlook OLE constants

WIN32OLE.const\_load(olapp, OutlookConst)

mymapi = olapp.GetNameSpace(“MAPI”) #Get the MAPI Object  
puts “Enter the name of the folder that you want to focus:”  
foldername=STDIN.gets  
#Get the folder name

foldername=foldername.strip  
foldername=foldername.upcase

#Remove Leading/Trailing Spaces and convert it to the uppercase

myfolder=0  
#Initialization

folders = mymapi.Folders

# Get the Base folder collection

folders.each {  
| folder |

```
if(folder.Name.upcase==foldername)
myfolder=folder
end

subfolder=folder.Folders

subfolder.each {
	| folder1 |
if(folder1.Name.upcase==foldername)
myfolder=folder1
end

sub2folder=folder1.Folders

sub2folder.each{
|folder2|
if(folder2.Name.upcase==foldername)
myfolder=folder2
end

}

}

```

}

if(myfolder==0)  
puts “No such folder found”  
else  
puts "“myfolder” is the handle for the required folder "  
myfolder.Display  
end

#olapp.quit  
#olapp=nil  
GC.start

Thanking You  
Srinivas
