You only need add a sentence for attach_rebuild_log
With this script you can attach AdventureWorks in the same folder where master exists.
DECLARE @data_path nvarchar(256);
DECLARE @db nvarchar(50);
DECLARE @filename nvarchar(100);
SET @data_path = (SELECT...