Read TSQL variable from Temp Table
Maybe you could try something like : 

declare @file varchar(50)
declare @DBName varchar(50)
declare @sql varchar(200)

CREATE TABLE #tempFileTable (FName VARCHAR(8000),Depth INTEGER, Files INTEGER)

INSERT INTO #tempFileTable
EXEC xp_dirtree 'D:\', 1, 1

select @file = FName
from #tempFileTable

set @DBName = 'MyDB'

set @sql = 'RESTORE DATABASE '+@DBName+' FROM  DISK = ''D:\'+@file+''' WITH  FILE = 1'

print @sql