Extract specific folder from zip file using node.js

I have a zip file with the following structure:

  • download.zip \ Temp \ abc.txt
  • download.zip \ Temp \ Foo \ abc2.txt

I want to extract the content under Temp

in download.zip into a directory, say D:\work_del

. This directory after extracting the zip should have abc.txt

and Foo\abc2.txt

I'm using the adm-zip node module, but that doesn't seem to help. (Below code is for reference).

var zip = require('adm-zip');

var file = new zip("D:\\Work\\download.zip");
file.extractEntryTo("Temp", 'D:\\Work_delete', false, true);

      

Any pointers to get the above script working in node.js?

+3


source to share


2 answers


var zip = require('adm-zip');

var file = new zip("D:\\Work\\download.zip");
file.extractEntryTo("Temp/abc.txt", 'D:\\Work_delete', false, true);

      

I noticed that if you give the path as Temp\\1.txt

it doesn't work. So try to avoid backslashes, as forward slashes work fine on Windows with Node.js.

var zip = require('adm-zip');

var file = new zip("C:/Users/harslo/Desktop/node/Download.zip");
file.extractEntryTo("Temp/abc.txt", 'C:/Users/harslo/Desktop/node/Work_delete', false, true);

      



If you want to extract all files inside a folder, use FolderName/

as described in the adm-zip docs docs.

PS - ADM-ZIP extractEntryTo doesn't seem to work with zip files created with Windows Inbuilt Send to ZIP.

+1


source


var zip = require('adm-zip');

var file = new zip("D:/Work/download.zip");
file.extractEntryTo("Temp/", "D:/Work_delete", false, true);

      



0


source







All Articles