Here is another version that should work pretty well.
http://jasonbrimhall.info/2014/01/14/t-sql-tuesday-050-automating-database-restores/
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events