I have the following code...
console.log("looking for "+ path+" "+fs.lstatSync(path).isDirectory());
with path == "/Volumes/Macintosh HD" I get
looking for /Volumes/Macintosh HD false
I also tried converting to "/Volumes/Macintosh\ HD" but then it can't even find the file.
Why is this not showing up as a directory?
This is because /Volumes/Macintosh HD
is actually a symlink to /
. It's not actually a directory.
You can do this instead:
console.log("looking for "+ path+" symlink: "+fs.lstatSync(path).isSymbolicLink());
// outputs: looking for /Volumes/Macintosh HD symlink: true
If you wanted to integrate this in your logic to check to see if the symlink is pointing to a directory, you can try something like this:
var path = '/Volumes/Macintosh HD';
if (fs.lstatSync(path).isSymbolicLink()) {
// replace 'path' with the real path if it's a symlink
path = fs.readlinkSync(path);
}
if (fs.lstatSync(path).isDirectory()) {
console.log('it is a directory!');
}