简体   繁体   中英

Extract a specific folder from a 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 to a directory say D:\\work_del . This directory after extraction of zip should have abc.txt and Foo\\abc2.txt I am using adm-zip module of node but that doesn't seem to help. (Below code 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 the scenario working in node.js?

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

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

The thing that I noticed is that if you specify the path as Temp\\\\1.txt it doesn't work. So try to avoid backslashes as forward slashes work perfectly fine in 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 the files inside of a folder use FolderName/ as described in adm-zip docs docs.

PS - ADM-ZIP extractEntryTo doesn't seem to be working with zips created with Windows Inbuilt "Send to ZIP".

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM