Script to Restore DB from Most Recent Backup

I'm trying to figure out a way to restore DB02 from the most recent backup of DB01.

Something like:

RESTORE DATABASE DB02
FROM DISK = 'Z:\SQLServerBackups\DB01XXXX.bak'

But DB01XXXX.bak will always be different obviously.

Hopefully that makes sense.
Thanks.

This is an old SP I used to use for restoring databases automatically you might be able to take ideas from it
http://www.nigelrivett.net/SQLAdmin/s_RestoreDatabase.html

If we have to restore latest backups we needed to find fully qualified backup file path, then we need to find its logical names then data & log file locations all these activities need to be carried out manually.

Check this ,this will be helpful for you .
https://www.ucartz.com/clients/index.php?rp=/knowledgebase/177/Fully-automated-SQL-Server-Restore-Script.html

Here is a simple way to restore the database to the point in time: http://www.sqlserverlogexplorer.com/sql-server-point-in-time-restore/