open recent file

Anybody know how to open one of the recently used blender files using python within blender?

if you have enabled in the user preferences that python commands to be visible and then go via the file menu open recent to a blend file you want to load from python script you can SEE the command.
Essentially with this result, filling in the good filepath:
bpy.ops.wm. open_mainfile(filepath=“filll in here the total bath you saw!”)

the recent files are stored in a simple text file:

import bpy
from os.path import exists, basename

fp = bpy.utils.user_resource('CONFIG', "recent-files.txt")

    with open(fp) as file:
        recent_files =
except (IOError, OSError, FileNotFoundError):
    recent_files = []
for f in recent_files:

Nice CoDEmaxN

Oh indeed recent-files exists within my config directory … only probably one small problem, because I am on W8 a filename looks like:
and that will probably not good, one has to double the \ or replace it by / (all) , right? NO it works (taken f out of ‘your’ recent_files list

(bedeutet DE Deutschland? :wink: ?)

They should be properly escaped, it’s the print() that “hides” it in output. You can use print(repr(f)) if you want to see it escaped.

Ja, tut es :wink:

the code above gave me this error:

Error:   File "\Text", line 10
    except IOError,OSError:

I used code to show the ^ at the right place , if not good it points to the comma.

it looks like, that the python in Blender 2.7* (?) needs
except (IOError,OSError):
to work (it does too with [] around the exception-reasons).

Sorry, I forgot to edit my post again, you need parenthesis as you said. Edited my post again, now properly catching exceptions and using “with” so we don’t need to care about to close the file.