Use temporary path variable in loop per @dirk-thomas 's suggestion