Moved path.resolve() call outside of loop