Below query can be used to restore multiple SQL Server databases using backup files.

SET NOCOUNT ON
DECLARE
@foldername Varchar (255) = 'D:\MSSQL\MSSQLSERVER', --path where .bak files are placed
@DataFileLocation Varchar(255) = 'E:\MSSQL' , -- Optional, Specifies the folder for 
Read the rest