How to Create SQL Agent Job to Automatically Restore Database from Latest Backups

backupjobsrestoresql server

There are 3 different folders which store respectively full, differential, and log backups. Different types of backups occur in different schedules. Now I need to create a new job which will periodically restore the database in order to assure the consistency of the backups. There are some third party tools available but I do not want to use them. Now, I can't figure out how to specify in the Job Step script to choose the last full/dif/log backups from their folders? The thing is there are multiple files already in the folders.