1

I'm using node-archiver to zip some files and in the zip file I find the archived files under the directory where was zipped from.

So in the zip file, 'myfile.txt' is under this sort of directory: 'home/ubuntu/some_folder/another_folder/' I want to have the files in the root directory of the zip file.

This is the code I suspect that is in charge with this:

archive.bulk(
   {src: filePaths}
);

Its documentation is here although I don't see how to do it.

Any ideas?

simon-p-r
  • 3,623
  • 2
  • 20
  • 35
George I.
  • 560
  • 2
  • 7
  • 26

1 Answers1

1

Just add expand:true, flatten:true and indicate what name you want to use for destination folder (dest: 'destinationfoldername/')

archive.bulk(
   {src: filePaths, dest:'destinationfoldername/', expand:true, flatten:true}
);

It workerd for me

Berio
  • 11
  • 1
  • the bulk() method is now deprecated. Do you know how to flatten file names (remove directories from them) using the glob() or directory() methods? – Robert Oschler Jun 27 '17 at 00:37
  • Not sure about glob, but for directory just supply an empty string as [`destpath`](https://www.archiverjs.com/archiver#directory): `.directory(dirpath, '')` – dwelle Dec 08 '20 at 21:52