Is this part only to test whether the path leads to a directory? In that case `fs.isDirectory` would be quicker, I suppose.