1

I'm using node-archiver to archive folder "export" with photos inside.

Everything works ok but inside archive I got folder 'offers' and photos are in this folder.

I would like to have like a "flat" .zip, so when I'll unpack my .zip it unpack photos without that 'offers' folder.

My code:

  const folderPath = '/export/.';
  const output = fs.createWriteStream('test/offers.zip');
  const archive = archiver('zip');
  archive.pipe(output);
  archive.directory(folderPath, false);
  archive.finalize();

What I'm getting after unpacking:

image1

What I would like to get:

image2

How can I achieve this?

Regards, Gemmi

Gemmi
  • 1,252
  • 2
  • 13
  • 26
  • 1
    I think that's because `/export/.` is the same as `/export` so it targets the folder, not the files inside. Try changing the path to `/export/*` – Seblor Mar 14 '19 at 16:22
  • Hi @Seblor, thx. I already tried that and with `*` node-archiver won't zipping my files. – Gemmi Mar 14 '19 at 16:26
  • 1
    Have you tried `archive.directory( 'export/' , false);` or `archive.glob( 'export/*.*' );` ? – Shilly Mar 14 '19 at 16:30
  • Oh right, I forgot it should be `.glob` not `.directory`, my bad. Good catch Shilly – Seblor Mar 14 '19 at 18:09
  • Thank you for replay @Shilly It doesn't work in any provided examples :/ – Gemmi Mar 14 '19 at 18:46

1 Answers1

2

All you need is set prefix via options property. Like this

archive.directory(folderPath, false, { prefix: 'your destination folder' });

Regards, Lukas