By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,441 Members | 1,725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,441 IT Pros & Developers. It's quick & easy.

Last used directory?

P: n/a
Hello:

Is there a global or some trick I can use to have
Python remember the last directory visited?
What I mean is suppose I have this function:

def get_filename():
""" Returns a filename selected from a Tkinter File Selection Dialog """
strFilename = tkFileDialog.askopenfilename(initialdir='.',
filetypes=[('Python
files','*.py'),
('All
Files','*.*')])
return strFilename

but instead of having initialdir='.' (current directory), I
would like it set to the last visited directory, which can be from a
previous run or even a previous day. Is that possible? If so how?
Thanks in advance:
Michael Yanowitz

Jul 12 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Wed, 12 Jul 2006 07:29:18 -0400, Michael Yanowitz wrote:
but instead of having initialdir='.' (current directory), I
would like it set to the last visited directory, which can be from a
previous run or even a previous day. Is that possible? If so how?
Every time you open a file, save the directory in a global variable. Then
instead of passing '.' as initialdir, pass that saved directory.

That will work while you're in the same session. To remember the last
visited directory from one session to the next, you'll need to write it to
some sort of permanent storage like a configuration file.

You'll also need to check what happens if the saved directory no longer
exists.
--
Steven.

Jul 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.