BagrijRoman
BagrijRoman

Reputation: 249

Node js. Writing directory to the archive, without path to this directory

Got some task, it is not hard, but i have some trouble. Maybe someone already has similar problem.

My task is writing to zip archive some folder, with files and other folders in it with using NodeJS

I try to use AdmZip pakage

folder project structure: enter image description here

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

let Archive = new AdmZip();
Archive.addLocalFolder('Archive/filesFolder', '');
Archive.writeZip('Archive/newArchive.zip);

I must get archive with 'filesFolder', instead i get archive with 'Archive' folder and in it i have 'filesFolder'.

If anybody know, how to record only target folder, and not the sequence of a way folders?

Upvotes: 0

Views: 1132

Answers (1)

Raf
Raf

Reputation: 7649

What happens is that you are providing Archive/filesFolder as value to writeZip and that means include in the zip Archive folder and inside that include filesFolder.

For testing purpose change the value of writeZip() to just filesFolder.zip and it should zip content of Archive as filesFolder.zip in current working directory. See below (you can copy/paste the bit of code and run it and it should work).

var zip = new AdmZip();
// I don't know why you provided a second argument to below, I removed it
// There was nothing about it in the documentation. 
zip.addLocalFolder('./Archive');

//rename the value of the following to just filesFolder.zip
zip.writeZip('filesFolder.zip');

The above should output the content of Archive to the current working directory as filesFolder.zip

I did mention this in my comment and your commend seem to indicate that you have path issue, so try the above script.

Upvotes: 1

Related Questions