# TK Directory question

**URL:** <https://www.ruby-forum.com/t/tk-directory-question/171260>\
**Category:** Ruby\
**Created:** [June 29, 2009, 5:53pm UTC](https://www.ruby-forum.com/t/tk-directory-question/171260 "2009-06-29T17:53:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@rubyman](https://www.ruby-forum.com/u/rubyman)\
**Post date:** [June 29, 2009, 5:53pm UTC](https://www.ruby-forum.com/t/tk-directory-question/171260/1 "2009-06-29T17:53:37Z")

</div>

Hello,

I am working on a GUI that allows the user to select a file to work on.  
I am using Tk.getOpenFile to do this. I would like the application to  
‘remember’ the file path from the last time they selected a file, so  
that the user does not have to browse to the same location over and  
over. I cannot find any info on how to do this.

Any help would be greatly appreciated. Thanks.

Harry

\_\_\_\_\_\_\_\_\_\_ Information from ESET NOD32 Antivirus, version of virus  
signature database 4196 (20090629) \_\_\_\_\_\_\_\_\_\_

The message was checked by ESET NOD32 Antivirus.

[http://www.eset.com](http://www.eset.com)

---

<div class="post-metadata">

**Author:** ![rubyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@rubyman](https://www.ruby-forum.com/u/rubyman)\
**Post date:** [June 29, 2009, 11:00pm UTC](https://www.ruby-forum.com/t/tk-directory-question/171260/2 "2009-06-29T23:00:50Z")

</div>

Hi,  
a way is

1. memorize into a var the last directory:

file = Tk.getOpenFile  
@last\_dir = File.dirname(file) if !file.nil?

1. use the option ‘initialdir’ of Tk.getOpenFile

file = Tk.getOpenFile(‘initialdir’=\>@last\_dir)

Antonio

Harry T. wrote:

> Hello,
> 
> I am working on a GUI that allows the user to select a file to work on.  
> I am using Tk.getOpenFile to do this. I would like the application to  
> ‘remember’ the file path from the last time they selected a file, so  
> that the user does not have to browse to the same location over and  
> over. I cannot find any info on how to do this.
> 
> Any help would be greatly appreciated. Thanks.
> 
> Harry
> 
> \_\_\_\_\_\_\_\_\_\_ Information from ESET NOD32 Antivirus, version of virus  
> signature database 4196 (20090629) \_\_\_\_\_\_\_\_\_\_
> 
> The message was checked by ESET NOD32 Antivirus.
> 
> [http://www.eset.com](http://www.eset.com)

---

<div class="post-metadata">

**Author:** ![rubyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@rubyman](https://www.ruby-forum.com/u/rubyman)\
**Post date:** [June 30, 2009, 1:34pm UTC](https://www.ruby-forum.com/t/tk-directory-question/171260/3 "2009-06-30T13:34:39Z")

</div>

Cool! Thank you very much!

Harry

----- Original Message -----  
From: “Antonio G.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: “ruby-talk ML” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Monday, June 29, 2009 5:01 PM  
Subject: Re: TK Directory question

> file = Tk.getOpenFile(‘initialdir’=\>@last\_dir)
> 
> > that the user does not have to browse to the same location over and  
> > The message was checked by ESET NOD32 Antivirus.
> 
> The message was checked by ESET NOD32 Antivirus.
> 
> [http://www.eset.com](http://www.eset.com)

\_\_\_\_\_\_\_\_\_\_ Information from ESET NOD32 Antivirus, version of virus  
signature database 4199 (20090630) \_\_\_\_\_\_\_\_\_\_

The message was checked by ESET NOD32 Antivirus.

[http://www.eset.com](http://www.eset.com)
