Reputation: 8114
I was trying to get the number of files in my zip file. I used adm-zip.So i tried using following:-
var unzip=require('adm-zip');
var zip=new unzip("hello.zip");
console.log(zip.getEntries().length);
Now in my hello.zip
file I have 5 files, but the count of zip.getEntries().length
is 6.
zip.getEntries()
returns array of objects from what I read. Can someone please help me on this? How I get the correct count of number of files?
Upvotes: 0
Views: 2649
Reputation: 12584
I am not sure why its giving 1 more than what's expected. I have 2 suggestions for you. Have a check at both.
Change the path of the file that you are planning to unzip to-
var zip=new unzip("./hello.zip");
Check if there are any hidden files or links(like the .git
)
Also, to answer your question on how to find the length, just validate the above points and also try this-
var zipEntries = zip.getEntries()
zipEntries.forEach(function(zipEntry) {
count++;
}
Hope it helps! :) Happy coding!
Upvotes: 1