Script working for matrix directory and file layout