standardize the robust use of makedirs (Fix #208)
merged master