Refactor #5580: Improve createDirectories