I think baseDir1 needs to be the string that matched inthe loop above.  If the first matched, and the second was different it would potentially corrupt the path.