ensureDir becomes a function