David Anastasi
David Anastasi

Reputation: 68

PhantomJS fs.list() returning wrong length

I am trying to get the number of files in a directory, but PhantomJS is returning more files than what exists. Am I missing something here? (I have no hidden files in this directory)

testNoOfFiles = fs.list(dir).length; 
console.log(testNoOfFiles);

This logs 7, when I have 5 files in the directory.

Upvotes: 2

Views: 44

Answers (1)

Artjom B.
Artjom B.

Reputation: 61932

. (current directory) and .. (parent directory) are also always part of the list. If you don't want to consider them, you can subtract 2 and always disregard the first two elements of fs.list() output. This is also the case on windows.

Upvotes: 2

Related Questions