Last used directory?

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Jul 12 08:15:04 EDT 2006


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.




More information about the Python-list mailing list