Make sure makedirs: True accounts for case where a trailing slash exists

Fix for #3828.